#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const double PI = 3.14159265358979323846;
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  string c[m];
  for (ll i = 0; i < (ll)(m); i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  for (ll i = 0; i < (ll)(pow(10, n)); i++) {
    bool flag = true;
    char ss[4];
    sprintf(ss, "%03d", i);
    string sss = ss;
    sss = sss.substr(3 - n, n);
    for (ll j = 0; j < (ll)(m); j++) {
      if ((c[j][0]) != sss[s[j] - 1]) {
        flag = false;
        break;
      }
    }
    if (flag && (sss[0] != '0')) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
