#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];
  vector<int> keta;
  for (int i = 0; i < (1000); ++i) {
    int tmp_num = i;
    keta.clear();
    while (tmp_num > 0) {
      keta.push_back(tmp_num % 10);
      tmp_num /= 10;
    }
    reverse(keta.begin(), keta.end());
    bool ok = true;
    for (int j = 0; j < (m); ++j) {
      for (int k = 0; k < (keta.size()); ++k) {
        if (s[j] == (k + 1)) {
          if (keta[k] != c[j]) {
            ok = false;
            break;
          }
        }
      }
      if (!ok) break;
    }
    if (ok) {
      if (n == 3 && i >= 100) {
        cout << i << endl;
        return 0;
      }
      if (n == 2 && i < 100 && i >= 10) {
        cout << i << endl;
        return 0;
      }
      if (n == 1 && i < 10) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
