#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < (int)(N); i++) cin >> s[i] >> c[i];
  int start;
  if (N == 1) {
    start = 0;
  } else {
    start = pow(10, N - 1);
  }
  for (int i = start; i < pow(10, N) - 1; i++) {
    bool ok = true;
    for (int j = 0; j < (int)(M); j++) {
      if (i / (int)pow(10, N - s[j]) % 10 != c[j]) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
