#include <bits/stdc++.h>
using namespace std;
bool kansuu(int num, pair<int, char> sc) {
  string str;
  str = to_string(num);
  if (sc.first > str.size()) {
    return false;
  }
  if (str[sc.first - 1] == sc.second) {
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> sc(m);
  for (int i = 0; i < m; i++) {
    int s_in;
    char c_in;
    cin >> s_in >> c_in;
    sc.at(i) = make_pair(s_in, c_in);
  }
  int ans = 0;
  bool flag = true;
  for (int num = 0; num < 1000; num++) {
    for (auto sc_ele : sc) {
      flag = (flag && kansuu(num, sc_ele));
      if (flag == false) {
        break;
      }
    }
    if (flag == true) {
      ans = num;
      break;
    }
  }
  if (ans == 0 && (flag == false)) {
    ans = -1;
  }
  cout << ans << endl;
}
