#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
const lint mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  std::vector<int> s(m);
  std::vector<int> c(m);
  for (int i = (0), i_end_ = (m); i < i_end_; i++) cin >> s[i] >> c[i];
  std::vector<int> num(n, -1);
  for (int i = (0), i_end_ = (m); i < i_end_; i++) {
    if (num[s[i] - 1] == -1) {
      num[s[i] - 1] = c[i];
    } else if (num[s[i] - 1] != c[i]) {
      cout << -1 << "\n";
      return 0;
    }
  }
  for (int i = (0), i_end_ = (n); i < i_end_; i++) {
    if (n != 1 && num[0] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (i != 0 && num[i] == -1) {
      num[i] = 0;
    } else if (i == 0 && num[i] == -1) {
      num[i] = 1;
    }
  }
  for (int i = (0), i_end_ = (n); i < i_end_; i++) cout << num[i];
  cout << "\n";
  return 0;
}
