#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> A;
  for (int i = 0; i < m; ++i) {
    int pos;
    char c;
    cin >> pos >> c;
    pos--;
    A.emplace_back(pos, c);
  }
  string ans = "-1";
  for (int i = 100; i < 1000; ++i) {
    string s = to_string(i);
    bool ok = true;
    for (int j = 0; j < m; ++j)
      if (s[A[j].first] != A[j].second) ok = false;
    if (ok) {
      ans = s;
      break;
    }
  }
  cout << ans << endl;
}
