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