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