#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> a(m);
  for (auto& i : a) {
    cin >> i.first >> i.second;
    i.first--;
  }
  for (int i = 0; i < 1000; i++) {
    string s = to_string(i);
    if (s.size() != n) continue;
    for (auto& i : a)
      if (s[i.first] != i.second) continue;
    cout << s << endl;
    return 0;
  }
  cout << -1 << endl;
}
