#include <bits/stdc++.h>
using namespace std;
void doit() {
  long long n, m = 0, i, a[5];
  a[1] = a[2] = a[3] = -1;
  cin >> n >> m;
  bool ok = 0;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    if (ok) continue;
    if (x == 1 && y == 0) {
      ok = 1;
      continue;
    }
    if (a[x] != -1) {
      if (a[x] != y) {
        ok = 1;
        continue;
      }
    }
    a[x] = y;
  }
  if (!ok && n == 1) {
    cout << max(a[1], 0LL) << "\n";
    return;
  }
  if (ok)
    cout << -1 << "\n";
  else {
    for (i = 1; i < n + 1; i++) {
      if (i == 1) {
        if (a[i] == -1)
          cout << 1;
        else
          cout << a[i];
        continue;
      }
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    doit();
  }
}
