#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<int> data(N, 0);
  vector<bool> dataResult(N, false);
  bool error = false;
  for (int i = 0; i < M; i++) {
    int keta;
    cin >> keta;
    int number;
    cin >> number;
    if ((dataResult[keta - 1] == true && data[keta - 1] != number) ||
        keta == 1 && number == 0 || keta > N) {
      error = true;
      break;
    } else {
      data[keta - 1] = number;
      dataResult[keta - 1] = true;
    }
  }
  int result = 0;
  int keta = 1;
  if (!error) {
    for (int i = N - 1; i >= 0; i--) {
      int tmp = i == 0 && data[i] == 0 ? 1 : data[i];
      result += tmp * keta;
      keta *= 10;
    }
  } else {
    result = -1;
  }
  cout << result << endl;
}
