#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(3, 0);
  vector<bool> b(3, false);
  bool flag = false;
  for (int i = 0; i < m; i++) {
    int c, d;
    cin >> c >> d;
    if (a[c - 1] != d && b[c - 1] == true) flag = true;
    a[c - 1] = d;
    b[c - 1] = true;
  }
  if (flag) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1 && a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (n != 1 && a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int k = pow(10, n - 1) - 1;
  int l = pow(10, n);
  for (int i = k; i < l; i++) {
    bool ans = true;
    int op = i;
    for (int i = 0; i < n; i++) {
      if (op % 10 != a[n - 1 - i]) ans = false;
      op /= 10;
    }
    if (ans) {
      cout << i << endl;
      return 0;
    }
  }
}
