#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  bool isOk;
  for (int i = 0; i < 1000; i++) {
    isOk = true;
    if (!((n == 1 && i < 10) || (n == 2 && 10 <= i && i < 100) ||
          (n == 3 && 100 <= i)))
      continue;
    vector<int> d;
    int num = i;
    do {
      d.push_back(num % 10);
      num /= 10;
    } while (num > 0);
    for (int i = 0; i < m; i++) {
      if (d[d.size() - s[i]] != c[i]) isOk = false;
    }
    if (isOk) {
      cout << i << endl;
      break;
    }
  }
  if (!isOk) cout << -1 << endl;
  return 0;
}
