#include <bits/stdc++.h>
using namespace std;
void yn(bool b) {
  if (b)
    printf("yes\n");
  else
    printf("no\n");
}
void Yn(bool b) {
  if (b)
    printf("Yes\n");
  else
    printf("No\n");
}
void YN(bool b) {
  if (b)
    printf("YES\n");
  else
    printf("NO\n");
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  vector<int> num(3, 0);
  int ans = 0;
  int flag = 0;
  for (int i = 0; i < 1000; i++) {
    flag = 0;
    for (int j = 0; j < M; j++) {
      if (s[j] == 3) {
        if (i % 10 != c[j]) flag = 1;
      }
      if (s[j] == 2) {
        if ((i / 10) % 10 != c[j]) flag = 1;
      }
      if (s[j] == 1) {
        if ((i / 100) != c[j]) flag = 1;
      }
    }
    if (flag == 0) {
      ans = i;
      break;
    }
  }
  if (flag = 1) ans = -1;
  cout << ans;
}
