#include <bits/stdc++.h>
using namespace std;
int func(int num) {
  int cnt = 1;
  while (num / 10 != 0) {
    cnt++;
    num /= 10;
  }
  return cnt;
}
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int d[M];
  for (int i = 0; i < M; i++) d[i] = N - s[i] + 1;
  int ans = 10001;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        bool is = true;
        int num = i * 100 + j * 10 + k;
        int n[] = {k, j, i};
        if (func(num) != N) is = false;
        for (int itr = 0; itr < N; itr++) {
          if (n[d[itr] - 1] != c[itr]) is = false;
        }
        if (is) ans = min(ans, num);
      }
    }
  }
  if (ans == 1001)
    cout << ans << endl;
  else
    cout << ans << endl;
  return 0;
}
