#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long inf = 1e18;
long long N, M;
long long s[10], c[10];
long long ans[3];
int main() {
  cin >> N >> M;
  for (long long i = (0); i < (3); i++) ans[i] = -1;
  for (long long i = (0); i < (M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (ans[s[i]] == -1) {
      ans[s[i]] = c[i];
    } else if (ans[s[i]] != c[i]) {
      cout << (-1) << endl;
      return 0;
    }
  }
  long long start = 0;
  long long end = 10;
  if (N == 2)
    start = 10, end = 100;
  else if (N == 3)
    start = 100, end = 1000;
  for (long long i = (start); i < (end); i++) {
    if ((ans[2] == -1 || ans[2] == (i % 10)) &&
        (ans[1] == -1 || ans[1] == ((i / 10) % 10)) &&
        (ans[0] == -1 || ans[0] == (i / 100))) {
      cout << (i) << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
  return 0;
}
