#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int keta[11];
  int num[11];
  for (int i = 0; i < M; i++) {
    cin >> keta[i] >> num[i];
  }
  int ans = -1;
  for (int i = 0; i < 1000; i++) {
    bool check = true;
    if (i < pow(10, N - 1) && i != 0) {
      check = false;
    }
    int I = i;
    int kari = i;
    int hun, ten, one;
    hun = 0;
    ten = 0;
    one = 0;
    if (N > 2) {
      hun = I % 10;
      I /= 10;
    }
    if (N > 1) {
      ten = I % 10;
      I /= 10;
    }
    if (N > 0) {
      one = I % 10;
      I /= 10;
    }
    for (int j = 0; j < M; j++) {
      if (1 == keta[j]) {
        if (one != num[j]) {
          check = false;
        }
      } else if (2 == keta[j]) {
        if (ten != num[j]) {
          check = false;
        }
      } else if (3 == keta[j]) {
        if (hun != num[j]) {
          check = false;
        }
      }
    }
    if (check == true) {
      ans = kari;
      break;
    }
  }
  cout << ans << endl;
}
