#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  bool ok = true;
  int minv = -1;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 999; i <= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (to_string(i).size() != n || to_string(i).at(s[j] - 1) != c[j]) {
        ok = false;
      }
    }
    if (ok) {
      minv = i;
    }
    ok = true;
  }
  cout << minv << endl;
}
