#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c;
  cin >> N >> M;
  vector<int> num = vector<int>(N, -1);
  bool exist = true;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s--;
    if (num.at(s) == -1) {
      num.at(s) = c;
    } else if (num.at(s) == c) {
    } else {
      exist = false;
    }
  }
  if (N != 1) {
    if (num.at(0) == -1) {
      num.at(0) = 1;
    } else if (num.at(0) == 0) {
      exist = false;
    }
    for (int i = 1; i < N; i++) {
      if (num.at(i) == -1) {
        num.at(i) = 0;
      }
    }
  }
  if (exist) {
    for (int i = 0; i < num.size(); i++) {
      cout << num.at(i);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
