#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (long long i = (0); i < (long long)(M); i++) cin >> s[i] >> c[i];
  vector<long long> ans(N + 1, -1);
  bool f = true;
  for (long long i = (0); i < (long long)(M); i++) {
    if (ans[s[i]] == -1) {
      ans[s[i]] = c[i];
    } else if (ans[s[i]] != c[i]) {
      f = false;
    }
  }
  if (!f) {
    cout << -1 << endl;
  } else if (N == 1 && ans[1] == 0) {
    cout << 0 << endl;
  } else if (ans[1] == 0) {
    cout << -1 << endl;
  } else {
    for (long long i = (1); i < (long long)(N + 1); i++) {
      if (ans[i] == -1)
        cout << 0;
      else
        cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
