#include <bits/stdc++.h>
using namespace std;
int mypow(int base, int times) {
  int i = 1;
  for (int j = 1; j < times; ++j) {
    i *= base;
  }
  return i;
}
int main() {
  int N, M;
  cin >> N;
  cin >> M;
  int max_number = 9;
  int min_number = 0;
  for (int i = 2; i <= N; ++i) {
    max_number = max_number * 10 + 9;
    min_number = (max_number + 1) / 10;
  }
  vector<int> requirements(M, -1);
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s;
    cin >> c;
    s--;
    if (requirements[s] != -1 && requirements[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    requirements[s] = c;
  }
  for (int i = min_number; i <= max_number; ++i) {
    bool fail = false;
    for (int j = 0; j < M; ++j) {
      int check = (i / mypow(10, N - j)) % 10;
      if (check != requirements[j] && requirements[j] != -1) fail = true;
    }
    if (fail)
      continue;
    else {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
