#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());
  long long b = 0;
  for (long long i = 0; i < m - 1; i++) {
    if (a[i].first == a[i + 1].first && a[i].second != a[i].second) b = 1;
  }
  if (b) {
    cout << -1 << endl;
    return 0;
  }
  a.erase(unique(a.begin(), a.end()), a.end());
  if (n == 1 && a[0].second == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (n == 2 || n == 3) {
    for (long long i = 0; i < m; i++) {
      if (a[i].first == 1 && a[i].second == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 1; i <= 999; i++) {
    if (keta(i) != n) continue;
    long long d = 1;
    string c = to_string(i);
    for (long long j = 0; j < m; j++) {
      if (c[a[j].first - 1] - '0' != a[j].second) {
        d = 0;
      }
    }
    if (d) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
