#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.at(i) >> c.at(i);
  }
  for (int i = 700; i <= 705; i++) {
    int digit = 0;
    if (i == 0) {
      digit = 1;
    } else {
      int tmp = i;
      while (tmp) {
        tmp /= 10;
        ++digit;
      }
    }
    if (N != digit) {
      continue;
    }
    string str = to_string(i);
    bool flag = true;
    for (int j = 0; j < (M); ++j) {
      if (str[s[j] - 1] != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
