#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long n, long long mod = 1000000007) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> cond(m, '#');
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (cond[s - 1] == '#') {
      cond[s - 1] = c;
    } else if (cond[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = modpow(10, n - 1) - (n == 1); i < modpow(10, n); i++) {
    string s = to_string(i);
    bool flag = true;
    for (int j = 0; j < min(n, m); j++) {
      if (cond[j] == '#') {
        continue;
      }
      flag &= (s[j] == cond[j]);
    }
    if (flag) {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
