#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i < (1000); i++) {
    bool ans = true;
    for (int j = 0; j < (m); j++) {
      string a = to_string(i);
      int keta = a.size();
      if (keta != n || a[s[j]] != c[j]) ans = false;
    }
    if (ans) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
