#include <bits/stdc++.h>
using namespace std;
long long keta(long long a) {
  long double b = a;
  b = log10(b);
  long long c = b;
  return c + 1;
}
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> a(m);
  for (long long i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());
  if (n == 0 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long x = 1;
  for (long long i = 0; i < n - 1; i++) {
    if (a[i].first == a[i + 1].first) {
      if (a[i].second != a[i + 1].second) {
        x = 0;
        break;
      }
    }
  }
  if (!x) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 2 || n == 3) {
    long long b = 0;
    for (long long i = 0; i < m; i++) {
      if (a[i].first == 1 && a[i].second == 0 ||
          a[i].first == 2 && a[i].second == 0) {
        b = 1;
        break;
      }
    }
    if (b) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    for (long long i = 0; i < m; i++) {
      if (a[i].second == 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  for (long long i = 1; i <= 999; i++) {
    if (keta(i) != n) continue;
    string f = to_string(i);
    long long c = 1;
    for (long long k = 0; k < m; k++) {
      if (f[a[k].first - 1] - '0' != a[k].second) {
        c = 0;
      }
    }
    if (c) {
      cout << f << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
