#include <bits/stdc++.h>
using namespace std;
int main() {
  string Ans = "";
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> S.at(i) >> C.at(i);
  }
  vector<string> A(N);
  for (int i = 0; i < (int)(N); i++) {
    A.at(i) = '0';
  }
  for (int i = 0; i < (int)(M); i++) {
    if (A.at(S.at(i) - 1) == "0") {
      A.at(S.at(i) - 1) = to_string(C.at(i));
    } else if (A.at(S.at(i) - 1) != to_string(C.at(i))) {
      Ans = "-1";
      break;
    }
  }
  if (A.at(0) == "0") {
    if (N == 2 || N == 3) {
      Ans = "-1";
    }
  }
  if (Ans == "-1") {
    cout << Ans << endl;
  } else {
    for (int i = 0; i < (int)(N); i++) {
      cout << A.at(i);
    }
    cout << endl;
  }
}
