#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N, M;
  cin >> N >> M;
  int s[10];
  int c[10];
  for (int i = 0; i < (int)(M); i++) cin >> s[i] >> c[i];
  int ans = -1;
  for (int i = 0; i < (int)(1000); i++) {
    int n[4];
    if ((i / 100) != 0) {
      if (N != 3) continue;
      n[1] = (i / 100);
      n[2] = ((i % 100) / 10);
      n[3] = ((i % 100) % 10);
    } else if ((i / 10) != 0) {
      if (N != 2) continue;
      n[1] = (i / 10);
      n[2] = (i % 10);
      n[3] = -10;
    } else {
      if (N != 1) continue;
      n[1] = i;
      n[2] = -10;
      n[3] = -10;
    }
    for (int j = 0; j < (int)(M); j++) {
      if (n[s[j]] != c[j]) {
        break;
      }
      if (j == M - 1) ans = i;
    }
    if (ans != -1) break;
  }
  cout << ans << endl;
}
