#include <bits/stdc++.h>
using namespace std;
long long a[20005];
long long exgcd(long long m, long long n, long long& x, long long& y) {
  if (n == 0) {
    x = 1, y = 0;
    return m;
  }
  long long r = exgcd(n, m % n, y, x);
  y -= m / n * x;
  return r;
}
int main() {
  long long n, m;
  while (cin >> n >> m) {
    int fa = 0;
    if (n == 1 && m == 0) {
      cout << 0 << endl;
      continue;
    }
    memset(a, -1, sizeof(a));
    for (int i = 1; i <= m; i++) {
      long long x, y;
      cin >> x >> y;
      if (a[x] != -1 && a[x] != y) {
        fa = 1;
      }
      a[x] = y;
    }
    if (a[1] == 0) fa = 1;
    if (a[1] == -1) a[1] = 1;
    if (fa)
      cout << -1 << endl;
    else {
      for (int i = 1; i <= n; i++) {
        if (a[i] != -1)
          cout << a[i];
        else
          cout << 0;
      }
      cout << endl;
    }
  }
}
