#include <bits/stdc++.h>
using namespace std;
int keta(int N) {
  int k = 1;
  while (N / 10 > 0) {
    N /= 10;
    k++;
  }
  return k;
}
int ketanum(int N, int num) {
  for (int i = 0; i < num - 1; i++) {
    N /= 10;
  }
  return N % 10;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int result = 1;
  for (int i = 0; i < N - 1; i++) {
    result *= 10;
  }
  int max = result * 10;
  int judgement = false;
  while (result < max) {
    bool judge = true;
    for (int i = 0; i < M; i++) {
      if (ketanum(result, N - s.at(i) + 1) != c.at(i)) judge = false;
    }
    if (judge) {
      judgement = true;
      break;
    }
    result++;
  }
  if (result == max && judgement == false)
    cout << "-1" << endl;
  else
    cout << result << endl;
}
