#include <bits/stdc++.h>
using namespace std;
long long aa[213456];
signed main() {
  long long n, m, a, b, sum = 0, ans = 0;
  string s;
  cin >> n >> m;
  for (long long h = 0; h < m; h++) {
    cin >> a >> b;
    if (a == 1 && b == 0) {
      sum = 1;
    }
    if (aa[a] == 0) {
      aa[a] = b + 1;
    } else {
      if (aa[a] != b) {
        sum = 1;
      }
    }
  }
  if (sum == 1) {
    cout << -1 << endl;
    return 0;
  }
  for (long long h = 1; h <= n; h++) {
    if (h == 1 && aa[h] == 1) {
      cout << 1;
    } else {
      cout << aa[h] - 1;
    }
  }
  cout << endl;
}
