#include <bits/stdc++.h>
using namespace std;
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];
  int ans = -1;
  for (int i = pow(10, (N - 1)); i < pow(10, N); ++i) {
    bool flag = true;
    for (int j = 0; j < M; ++j) {
      if (to_string(i)[s[j] - 1] != c[j]) flag = false;
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
