#include <bits/stdc++.h>
using namespace std;
int N, M;
void i_to_array(int x, int a[]) {
  for (int i = 0; i < N; i++) {
    a[i] = x / (int)pow(10, N - 1 - i);
    x -= a[i] * (int)pow(10, N - 1 - i);
  }
  return;
}
int main() {
  cin >> N >> M;
  int s[6], c[6];
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int a[3] = {-1, -1, -1};
  int max_N = 1, min_N;
  for (int i = 0; i < N; i++) max_N *= 10;
  if (N == 1)
    min_N = 0;
  else {
    min_N = max_N / 10;
  }
  int ans = -1;
  bool check = true;
  for (int i = min_N; i < max_N; i++) {
    i_to_array(i, a);
    for (int j = 0; j < M; j++) {
      if (a[s[j] - 1] == -1 || a[s[j] - 1] == c[j])
        a[s[j] - 1] = c[j];
      else
        check = false;
    }
    if (check) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
