#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) {
    bool flg = true;
    for (int j = 0; j < (m); ++j) {
      int tmp_num = i;
      for (int k = 3; k > 0; --k) {
        if (s[j] == k && tmp_num % 10 != c[j]) {
          flg = false;
          break;
        }
        tmp_num /= 10;
      }
      if (!flg) break;
    }
    if (flg) {
      if (i >= 100 && n == 3) {
        cout << i << endl;
        return 0;
      } else if (i >= 10 && i < 100 && n == 2) {
        cout << i << endl;
        return 0;
      } else if (i < 10 && n == 1) {
        cout << i << endl;
        return 0;
      } else {
        continue;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
