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