#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  string str;
  bool jud;
  cin >> N >> M;
  str = "0000000000";
  jud = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (str.at(s - 1) != '0' && str.at(s - 1) != c + '0') {
      jud = false;
    }
    str.at(s - 1) = c + '0';
  }
  if (str.at(0) == '0') {
    jud = false;
  }
  if (jud) {
    for (int i = 0; i < N; i++) cout << str.at(i);
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
