#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::make_pair;
using std::map;
using std::string;
using std::terminate;
void solve() {
  int n, m;
  cin >> n >> m;
  map<int, char> dic;
  for (int a = 1; a <= m; ++a) {
    int s;
    cin >> s;
    s--;
    char c;
    cin >> c;
    map<int, char>::iterator it = dic.find(s);
    if (it != dic.end()) {
      if (it->second != c) {
        cout << -1 << endl;
        return;
      }
    } else {
      dic.insert(make_pair(s, c));
    }
  }
  if (dic.find(0) == dic.end()) {
    cout << -1 << endl;
    return;
  } else {
    if (dic.find(0)->second == '0') {
      cout << -1 << endl;
      return;
    }
    string str;
    str.append(n, '0');
    for (decltype(dic)::iterator it = dic.begin(); it != dic.end(); ++it) {
      str[it->first] = it->second;
    }
    cout << str << endl;
  }
}
int main() {
  solve();
  return 0;
}
