#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> si(M), ci(M);
  bool judge = false;
  for (int i = 0; i < (int)(M); i++) {
    cin >> si.at(i);
    cin >> ci.at(i);
    if (si.at(i) == 1 && ci.at(i) != 0) {
      judge = true;
    }
  }
  if (N = 1 && ci.at(0) != 0) {
    judge = true;
  }
  for (int i = 0; i < (int)(M); i++) {
    for (int j = 0; j < (int)(M); j++) {
      if (i != j) {
        if (si.at(i) == si.at(j) && ci.at(i) != ci.at(j)) {
          judge = false;
        }
      }
    }
  }
  map<int, int> output;
  if (judge == true) {
    for (int i = 0; i < (int)(M); i++) {
      output[si.at(i)] = ci.at(i);
    }
  }
  string outputstring;
  for (int i = 0; i < (int)(N); i++) {
    if (output[i + 1] != 0) {
      outputstring += to_string(output[i + 1]);
    } else {
      outputstring += "0";
    }
  }
  if (judge)
    cout << outputstring << endl;
  else
    cout << "-1" << endl;
}
