#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
using vvi = vector<vi>;
long long n, m, x, y;
int main() {
  long long ans = 0;
  cin >> n >> m;
  vi s(m), c(m);
  vi ke(3, -1);
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (ke[n - s[i]] == -1) {
      ke[n - s[i]] = c[i];
    } else {
      if (ke[n - s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 0; i < 3; i++) {
    if (ke[i] == -1) {
      if (n == i + 1) {
        ke[i] = 1;
      } else {
        ke[i] = 0;
      }
    }
  }
  ans = ke[0] + ke[1] * 10 + ke[2] * 100;
  int nn = 1;
  if (n == 1) nn = 0;
  if (n == 2) nn = 10;
  if (n == 3) nn = 100;
  if (ans >= nn) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
