#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int S[M];
  int C[M];
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    S[i] = s;
    C[i] = c;
  }
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        for (int n = 0; n < M; n++) {
          if (S[n] == 1) {
            if (i != C[n]) break;
          } else if (S[n] == 2) {
            if (j != C[n]) break;
          } else if (S[n] == 3) {
            if (k != C[n]) break;
          }
          if (N == 3 && i == 0) break;
          if (N == 2 && j == 0) break;
          if (n == M - 1) {
            if (i == 0) {
              if (j == 0)
                cout << k << endl;
              else
                cout << j << k << endl;
            } else
              cout << i << j << k << endl;
            return (0);
          }
        }
      }
    }
  }
  cout << -1 << endl;
  return (0);
}
