#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 10000;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int(i) = 0; (i) < (m); ++(i)) cin >> s[i] >> c[i];
  for (int i = pow(10, n - 1); i < pow(10, n); ++i) {
    string str = to_string(i);
    bool check = true;
    for (int(j) = 0; (j) < (m); ++(j)) {
      if (str[s[j] - 1] != c[j]) check = false;
    }
    if (check) ans = min(ans, i);
  }
  if (ans == 10000) ans = -1;
  cout << ans << endl;
  return 0;
}
