#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
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 = 0; i < (1000); i++) {
    bool flag = 1;
    string str = to_string(i);
    int l = str.size();
    for (int j = 0; j < (m); j++) {
      if (s.at(j) > l)
        flag = 0;
      else {
        if (str.at(s.at(j) - 1) != c.at(j)) flag = 0;
      }
    }
    if (flag == 1) {
      cout << i << endl;
      break;
    }
    if (i == 999) {
      cout << -1 << endl;
    }
  }
}
