#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, -1);
  for (int i = 0; i < M; i++) {
    int si, ci;
    cin >> si >> ci;
    si--;
    if ((num[si] != -1) && (num[si] != ci)) {
      cout << -1;
      return 0;
    }
    num[si] = ci;
  }
  bool first_val = true;
  for (int j = 0; j < N; j++) {
    if ((j == 0) && (num[j] == 0)) {
      cout << -1;
      return 0;
    } else if ((num[j] == 0) && first_val) {
      num[j - 1] = 1;
    }
    if (num[j] != -1) first_val = false;
    if (num[j] == -1) {
      num[j] = 0;
    }
  }
  cout << (num[0] * 100) + (num[1] * 10) + num[2] << endl;
}
