#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
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.at(i) >> c.at(i);
  int ans;
  bool flag1, flag2, flag3;
  for (int i = 0; i <= 9; i++) {
    flag1 = 1;
    for (int j = 0; j < (m); j++) {
      if (s.at(j) != 1) {
        flag1 = 0;
        continue;
      }
      if (c.at(j) != i) {
        flag1 = 0;
        continue;
      }
    }
    if (flag1 == 1) {
      ans = i;
      cout << ans << endl;
      break;
    }
  }
  if (flag1 = 0) {
    for (int i = 10; i <= 99; i++) {
      flag2 = 1;
      for (int j = 0; j < (m); j++) {
        if (s.at(j) == 3) {
          flag2 = 0;
          continue;
        }
        if (s.at(j) == 2 && (i & 100) / 10 != c.at(j)) {
          flag2 = 0;
          continue;
        }
        if (s.at(j) == 1 && i / 100 != c.at(j)) {
          flag2 = 0;
          continue;
        }
      }
      if (flag2 == 1) {
        ans = i;
        cout << ans << endl;
        break;
      }
    }
  }
  if (flag1 == 0 && flag2 == 0) {
    for (int i = 100; i <= 999; i++) {
      flag3 = 1;
      for (int j = 0; j < (m); j++) {
        if (s.at(j) == 3 && (i % 10) != c.at(j)) {
          flag3 = 0;
          continue;
        }
        if (s.at(j) == 2 && (i % 100) / 10 != c.at(j)) {
          flag3 = 0;
          continue;
        }
        if (s.at(j) == 1 && (i / 100) != c.at(j)) {
          flag3 = 0;
          continue;
        }
      }
      if (flag3 == 1) {
        cout << i << endl;
        break;
      }
    }
  }
  if (flag1 == 0 && flag2 == 0 && flag3 == 0) cout << -1 << endl;
}
