#include <bits/stdc++.h>
using namespace std;
long long int F(long long int a, long long int b) {
  if (b == 1) return a / 100;
  if (b == 2) return (a - 100 * (a / 100)) / 10;
  if (b == 3) return a % 10;
}
int main() {
  long long int N, M;
  cin >> N >> M;
  vector<long long int> s(M);
  vector<long long int> c(M);
  for (long long int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (long long int n = pow(10, N - 1); n < pow(10, N); n++) {
    int count = 0;
    for (long long int i = 0; i < M; i++) {
      if (F(n, s[i]) == c[i]) count++;
    }
    if (count == M) {
      cout << n;
      exit(0);
    }
  }
  cout << -1;
}
