#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < (0 + m); i++) {
    cin >> s[i] >> c[i];
  }
  int ans_i = 0;
  for (int i = 0; i < (0 + 1000); i++) {
    int _1, _2, _3;
    _1 = i % 10;
    _2 = (i % 100 - _1) / 10;
    _3 = (i % 1000 - _1 - _2) / 100;
    if (_3 == 0 && n == 3) {
      continue;
    }
    if (_3 == 0 && _2 == 0 && n == 2) {
      continue;
    }
    bool ans2 = true;
    for (int j = 0; j < (0 + m); j++) {
      if (s[j] == 1 && _3 != c[j]) {
        ans2 = false;
      } else if (s[j] == 2 && _2 != c[j]) {
        ans2 = false;
      } else if (s[j] == 3 && _1 != c[j]) {
        ans2 = false;
      }
    }
    if (ans2) {
      ans_i = i;
      break;
    }
  }
  if (ans_i > 0) {
    cout << ans_i << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
