#include <bits/stdc++.h>
using namespace std;
int Max = 1000000;
int power(int n) {
  if (n == 0)
    return 1;
  else
    return 10 * power(n - 1);
}
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int Mrange = power(N);
  int mrange = power(N - 1);
  for (int k = mrange; k < Mrange; k++) {
    int a[N];
    int i = 0;
    int tmp = k;
    while (tmp > 0) {
      a[i] = tmp % 10;
      tmp /= 10;
      i++;
    }
    bool check = true;
    for (int j = 0; j < M; j++) {
      if (a[N - s[j]] != c[j]) check = false;
    }
    if (check) {
      cout << k << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
