#include <bits/stdc++.h>
using namespace std;
int mas[3]{-1, -1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--;
    if (mas[a] != -1 && mas[a] != b) {
      goto NO;
    }
    mas[a] = b;
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    string cur = to_string(i);
    bool ok = true;
    for (int j = 0; j < cur.size(); j++) {
      if (mas[j] == -1) continue;
      if (mas[j] != cur[j] - '0') ok = false;
    }
    if (ok) {
      cout << i << '\n';
      return 0;
    }
  }
NO:
  cout << -1 << '\n';
  return 0;
}
