#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, j = 1, k = 1;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < N - 1; i++) j *= 10;
  for (int i = 0; i < N; i++) k *= 10;
  for (int i = j; i < k; i++) {
    bool ans = true;
    string ss = to_string(i);
    for (int i = 0; i < M; i++) {
      if (ss[s[i] - 1] - '0' != c[i]) ans = false;
    }
    if (ans) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
