#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  while (m--) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 and c == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      if (a[s] != -1 and a[s] != c) {
        cout << -1 << endl;
        return 0;
      } else {
        a[s] = c;
      }
    }
  }
  if (n == 1) {
    a[0] = max(0, a[0]);
  } else {
    if (a[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else if (a[0] == -1) {
      a[0] = 1;
    }
    for (int i = 1; i < n + 1; i++) {
      a[i] = max(0, a[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans *= 10;
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
