#include <bits/stdc++.h>
using namespace std;
int d[10];
int main() {
  memset(d, -1, sizeof d);
  int n, m;
  cin >> n >> m;
  if (n == 1 and m == 0) return puts("0"), 0;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    d[s] = c;
  }
  for (int i = 0; i < 1000000; ++i) {
    if ((int)log10(i) + 1 != n) continue;
    string x = to_string(i);
    bool flag = 1;
    for (int j = 0; j < (int)x.size(); ++j)
      flag &= (x[j] == d[j] + '0' or d[j] == -1);
    if (flag) return cout << i << "\n", 0;
  }
  cout << -1 << "\n";
  return 0;
}
