#include <bits/stdc++.h>
using namespace std;
set<int> condition[4];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, a, b;
  vector<pair<int, int>> v;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    condition[a].insert(b);
    if (condition[a].size() > 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (int num = pow(10, n - 1); num < pow(10, n); num++) {
    bool ok = true;
    string s;
    int t = num;
    while (t > 0) {
      s = (char)(t % 10 + '0') + s;
      t /= 10;
    }
    for (int j = 0; j < 3; j++) {
      if (condition[j + 1].empty()) {
        continue;
      }
      if (*condition[j + 1].begin() != s[j] - '0') {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << num << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
