#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans, i, N3, N2, N1, t, judge;
  cin >> N >> M;
  int s[M], c[M];
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (ans = 0; ans < 1000; ans++) {
    if (N == 3) {
      N1 = ans / 100;
      t = ans / 10;
      N2 = t % 10;
      N3 = ans % 10;
    } else if (N == 2) {
      N1 = ans / 10;
      N2 = ans % 10;
      N3 = 0;
    } else if (N == 1) {
      N1 = ans;
      N2 = 0;
      N3 = 0;
    }
    for (i = 0; i < M; i++) {
      switch (s[i]) {
        case 1:
          if (c[i] == N1) {
            judge++;
          }
          break;
        case 2:
          if (c[i] == N2) {
            judge++;
          }
          break;
        case 3:
          if (c[i] == N3) {
            judge++;
          }
          break;
      }
    }
    if (judge == M) {
      cout << ans;
      goto end;
    }
    judge = 0;
  }
  cout << "-1";
end:;
}
