#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  bool answered = false;
  for (int i = 1; i < 1000; i++) {
    bool flag = true;
    string pre = to_string(i);
    for (int j = 0; j < M; j++) {
      if (s[j] == 1) {
        if (c[j] != pre[0]) {
          flag = false;
        }
      }
      if (s[j] == 2) {
        if (c[j] != pre[1]) {
          flag = false;
        }
      }
      if (s[j] == 3) {
        if (c[j] != pre[2]) {
          flag = false;
        }
      }
    }
    if (flag) {
      cout << pre << endl;
      answered = true;
      break;
    }
  }
  if (answered == false) {
    cout << -1 << endl;
  }
}
