#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) cin >> s[i] >> c[i];
  int first = 1;
  if (N >= 2) first *= 10;
  if (N >= 3) first *= 10;
  int last = 10;
  if (N >= 2) last *= 10;
  if (N >= 3) last *= 10;
  int ans = -1;
  for (int num = first; num < last; ++num) {
    string num_str = to_string(num);
    bool ok = true;
    for (int m = 0; ok && m < M; ++m) {
      if (num_str[s[m] - 1] - '0' != c[m]) ok = false;
    }
    if (ok) {
      ans = num;
      break;
    }
  }
  cout << ans << endl;
}
