#include <bits/stdc++.h>
using namespace std;
int fig(int a) {
  if (a < 10) return 1;
  if (a < 100) return 2;
  if (a < 1000) return 3;
}
int main() {
  int N, M, s[6], c[6], i, j;
  bool chk;
  string num;
  cin >> N >> M;
  for (i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (i = 0; i < 1000; i++) {
    chk = true;
    for (j = 0; j < M; j++) {
      if (s[j] > fig(i) || fig(i) != N) {
        chk = false;
        break;
      }
      num = to_string(i);
      if (num[s[j] - 1] != to_string(c[j])[0]) {
        chk = false;
        break;
      }
    }
    if (chk == true) {
      cout << num << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
