#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e18;
int64_t mod1 = 1e9 + 5;
int64_t power(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;
  else
    return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %
           mod;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t n, m;
  cin >> n >> m;
  int64_t x[n + 1];
  memset(x, -1, sizeof(x));
  for (int64_t i = 0; i < m; ++i) {
    int64_t a, b;
    cin >> a >> b;
    if (x[a - 1] != -1) {
      cout << -1;
      return 0;
    }
    x[a - 1] = b;
  }
  for (int64_t i = 0; i <= 999; i++) {
    vector<int64_t> v;
    if (i == 0) {
      v.push_back(0);
    } else {
      int64_t te = i;
      while (te) {
        v.push_back(te % 10);
        te /= 10;
      }
      reverse(v.begin(), v.end());
    }
    if (v.size() != n) {
      continue;
    }
    int64_t ch = 0;
    for (int64_t i = 0; i < v.size(); i++) {
      if (x[i] == -1) continue;
      if (x[i] != v[i]) {
        ch = 1;
        break;
      }
    }
    if (ch == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
