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