#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 if (l[s] != c) {
      f = false;
    } else {
      l[s] = c;
    }
  }
  if (l[3 - n] == 0 && n != 1) f = false;
  bool flag = true;
  for (int i = 0; i < (pow(10, n)); ++i) {
    if (l[2] != -1) {
      if (i % 10 != l[2]) {
        flag = false;
      }
    }
    if (l[1] != -1) {
      if ((i / 10) % 10 != l[1]) {
        flag = false;
      }
    }
    if (l[0] != -1) {
      if (i / 100 != l[0]) {
        flag = false;
      }
    }
    if (flag && i >= pow(10, n - 1)) {
      ans = min(ans, i);
    }
    flag = true;
  }
  if (f && ans != 1000) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
