#include <bits/stdc++.h>
using namespace std;
const int maxM = 10;
int N, M;
int Q[maxM][2];
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> Q[i][0] >> Q[i][1];
  }
  int start = pow(10, N - 1);
  int end = pow(10, N);
  if (N == 1) start = 0;
  for (int x = 0; x < 1000; x++) {
    bool chk = true;
    for (int i = 0; i < M; i++) {
      int y = x;
      int s, c;
      s = Q[i][0];
      c = Q[i][1];
      s = N - s + 1;
      if (s == 3) {
        y /= 100;
        if (y != c) chk = false;
      } else if (s == 2) {
        y /= 10;
        y %= 10;
        if (y != c) chk = false;
      } else if (s == 1) {
        y %= 10;
        if (y != c) chk = false;
      }
    }
    if (chk) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
