#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, ans = 1000;
  cin >> n >> m;
  int s, c;
  bool f = true;
  vector<int> l(3, -1);
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    s--;
    if (l[s] == -1 || l[s] == c) {
      l[s] = c;
    } else {
      f = false;
    }
  }
  if (l[0] == 0 && n != 1) f = false;
  bool flag = true;
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    if (i == 1) i = 0;
    if (l[2] != -1) {
      if (i % 10 != l[2]) {
        flag = false;
      }
    }
    if (l[1] != -1) {
      if (to_string(i)[1] != to_string(l[1])[1]) {
        flag = false;
      }
    }
    if (l[0] != -1) {
      if (to_string(i)[0] != to_string(l[0])[0]) {
        flag = false;
      }
    }
    if (flag && to_string(i).size() == n) {
      ans = min(ans, i);
    }
    flag = true;
  }
  if (f && ans != 1000) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
