#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < (1000); ++i) {
    if (n >= 3 && i < 100) continue;
    if (n >= 2 && i < 10) continue;
    int tmp_num = i;
    vector<int> keta(3);
    int j = 0;
    while (tmp_num > 0) {
      keta[j] = tmp_num % 10;
      tmp_num /= 10;
      ++j;
    }
    bool ok = true;
    for (int j = 0; j < (m); ++j) {
      for (int k = 3; k > 0; --k) {
        if (s[j] == k) {
          if (keta[3 - k] != c[j]) {
            ok = false;
            break;
          }
        }
      }
      if (!ok) break;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
