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