#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }
  bool flag = 0;
  vector<pair<int, bool>> A(N);
  for (int i = 0; i < M; i++) {
    if (!A.at(S.at(i) - 1).second) {
      A.at(S.at(i) - 1).first = C.at(i);
      A.at(S.at(i) - 1).second = true;
    } else if (A.at(S.at(i) - 1).first != C.at(i)) {
      flag = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i).first == 0 && A.at(i).second == 0) {
      A.at(i).first = 1;
      break;
    } else if (A.at(i).first != 0) {
      break;
    }
  }
  if (flag) {
    cout << -1 << endl;
  } else if (A.at(0).first == 0 && A.at(0).second == 1) {
    cout << -1 << endl;
  } else if (A.at(0).first == 0 && A.at(0).second == 0) {
    A.at(0).first = 1;
    for (int i = 0; i < N; i++) {
      cout << A.at(i).first;
    }
    cout << endl;
  } else {
    for (int i = 0; i < N; i++) {
      cout << A.at(i).first;
    }
    cout << endl;
  }
}
