#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
const long long INF = 2000000000ll;
long power(long a, long b) {
  return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1;
}
long comb(int N, int K) {
  long x = 1, y = 1;
  for (int i = 1; i <= K; i++) {
    x = x * (N - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * power(y, MOD - 2) % MOD;
}
long hcomb(int N, int K) { return comb(N + K - 1, N - 1); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N, M, chk = 1;
  cin >> N >> M;
  vector<char> S(N, '0');
  vector<int> s(M), c(M), temp(N, 0);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  for (int i = 0; i < 1000; i++) {
    chk = 1;
    string num = to_string(i);
    for (int j = 0; j < M; j++) {
      if (num[s[i] - 1] != c[i]) chk = 0;
    }
    if (chk) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
