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