#include <bits/stdc++.h>
using namespace std;
int m, n, s, c;
map<int, int> a;
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (s > n || (a.count(s) && a[s] != c)) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
  }
  if (n == 1 && !a.count(1)) cout << 0 << endl;
  if (n != 1 && a.count(1) && a[1] == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    cout << a[1];
    for (int i = (int)(2); i < (int)(n + 1); i++)
      if (a.count(i))
        cout << a[i];
      else
        cout << 0;
    cout << endl;
  }
  return 0;
}
