#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  char ans[5];
  int s[6], c[6];
  for (int i = 1; i <= M; i++) cin >> s[i] >> c[i];
  int cfl = 0;
  if (N == 1) {
    for (int i = 1; i <= 9; i++) {
      sprintf(ans + 1, "%d", i);
      int flag = 1;
      for (int j = 1; j <= M; j++) {
        if (ans[s[j]] != '0' + c[j]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1) {
        cout << i << endl;
        cfl = 1;
        break;
      }
    }
  } else if (N == 2) {
    for (int i = 10; i <= 99; i++) {
      sprintf(ans + 1, "%d", i);
      int flag = 1;
      for (int j = 1; j <= M; j++) {
        if (ans[s[j]] != '0' + c[j]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1) {
        cout << i << endl;
        cfl = 1;
        break;
      }
    }
  } else if (N == 3) {
    for (int i = 100; i <= 999; i++) {
      sprintf(ans + 1, "%d", i);
      int flag = 1;
      for (int j = 1; j <= M; j++) {
        if (ans[s[j]] != '0' + c[j]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1) {
        cout << i << endl;
        cfl = 1;
        break;
      }
    }
  }
  if (cfl == 0) cout << -1 << endl;
}
