#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int m = 0; m < M; m++) {
    cin >> s[m] >> c[m];
  }
  int startnum = 1;
  for (int n = 1; n < N; n++) {
    startnum *= 10;
  }
  int endnum = startnum * 10 - 1;
  for (int n = startnum; n <= endnum; n++) {
    bool allok = true;
    for (int i = 0; i < M; i++) {
      int kirisute = n;
      for (int count = 0; count < N - s[i]; count++) {
        kirisute /= 10;
      }
      if (kirisute % 10 == c[i])
        ;
      else {
        allok = false;
        break;
      }
    }
    if (allok) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
