#include <bits/stdc++.h>
using namespace std;
long int gcd(long int a, long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void Ok() {
  long long int a[1013], b[1013], c, d, e, f, g, h, t, i,
      j = 0, k, l1, l2, m, n, x, y, sum, ans_1, ans_2, ans_3, cnt = 0, Max, Min,
      flag, div, rcv, temp;
  long double aa, bb, cc, dd, ee, ff, gg;
  char aaa[1013], bbb[1013], ccc[1013], alpbt;
  string spc;
  cin >> n >> m;
  memset(a, -1, sizeof(a));
  Max = 0;
  flag = 0;
  for (i = 1; i <= m; i++) {
    cin >> c >> d;
    Max = max(Max, c);
    if (a[c] == -1)
      a[c] = d;
    else if (a[c] != -1 && c != 1) {
      if (a[c] == d) {
        a[c] = d;
      } else {
        flag = 1;
      }
    }
  }
  ans_1 = 0;
  if (flag)
    cout << "-1" << endl;
  else {
    for (i = 1; i <= Max; i++) {
      if (a[i] == -1) a[i] = 0;
    }
    for (i = 1; i <= Max; i++) {
      if (a[1] == 0) {
        cout << "-1" << endl;
        return;
      } else
        cout << a[i];
    }
    cout << endl;
  }
  return;
}
int main() {
  Ok();
  return 0;
}
