#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<string> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  string res = "";
  for (int i = 0; i < n; i++) {
    res += "?";
  }
  for (int i = 0; i < m; i++) {
    int digit = s.at(i) - 1;
    string target = {res[digit]};
    string tmp = c.at(i);
    if (target == "?" || target == tmp) {
      res.replace(digit, 1, tmp);
    } else {
      res = "-1";
      break;
    }
  }
  if (res[0] == '0') {
    res = "-1";
  }
  for (int i = 0; i < n; i++) {
    if (res[i] == '?') {
      res.replace(i, 1, "0");
    }
  }
  cout << res << endl;
}
