#include <bits/stdc++.h>
using namespace std;
int take_digit(int n, int s) {
  if (s == 1) {
    return n / 100;
  }
  if (s == 2) {
    return n / 10 % 10;
  }
  if (s == 3) {
    return n % 10;
  }
  return -1;
}
bool is_correct(int n, int N) {
  if (n == 0 && N == 1) {
    return true;
  }
  int range = n / pow(10, N - 1);
  return 1 <= range && range < 10;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> d(M);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    d[i] = make_pair(s, c);
  }
  int ans = -1;
  for (int n = 0; n <= 999; n++) {
    bool match = true;
    for (int i = 0; i < M; i++) {
      if (take_digit(n, d[i].first) != d[i].second) {
        match = false;
      }
    }
    if (match && is_correct(n, N)) {
      ans = n;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
