#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  vector<bool> zero(n, false);
  for (int j = 0; j < m; ++j) {
    cin >> a[j] >> b[j];
    --a[j];
    if (b[j] == 0) zero[a[j]] = true;
  }
  {
    for (int j = 0; j < m - 1; ++j) {
      if (!zero[j]) break;
      if (zero[j] && !zero[j + 1]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int j = 0; j < m - 1; ++j) {
    for (int k = j + 1; k < m; ++k) {
      if (a[j] == a[k] && b[j] != b[k]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < 1000; ++i) {
    int d = 0, nn = i;
    while (nn) {
      nn /= 10;
      ++d;
    }
    nn = i;
    int x[n];
    for (int j = n - 1; j >= 0; --j) {
      x[j] = nn % 10;
      nn /= 10;
    }
    if (d != n) continue;
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      if (x[a[j]] != b[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
