#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<P> p(M);
  for (int i = 0; i < (M); ++i) {
    P tp;
    cin >> tp.first;
    cin >> tp.second;
    p[i] = tp;
  }
  int start, end;
  start = (N == 1) ? 0 : (N == 2) ? 10 : 100;
  end = (N == 1) ? 9 : (N == 2) ? 99 : 999;
  int ans;
  ans = (M == 0) ? start : -1;
  for (int i = start; i < (end); ++i) {
    string num = to_string(i);
    for (int j = 0; j < (M); ++j) {
      P tp = p[j];
      if (num[tp.first - 1] != to_string(tp.second)[0]) break;
      if (j == M - 1) ans = i;
    }
    if (ans != -1) break;
  }
  cout << ans << endl;
  return 0;
}
