#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 s, c;
    cin >> s >> c;
    if (num.at(s - 1) == -1 || num.at(s - 1) == c)
      num.at(s - 1) = c;
    else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (num.at(0) == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (num.at(0) == -1)
    num.at(0) = 1;
  for (int i = 0; i < num.size(); i++) {
    if (num.at(i) == -1) num.at(i) = 0;
    cout << num.at(i);
  }
  cout << endl;
}
