#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> sc(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> sc.at(i).at(0) >> sc.at(i).at(1);
  }
  bool can = true;
  for (int i = 0; i < M; i++) {
    if (sc.at(i).at(0) == 1 && sc.at(i).at(1) == 0 && N != 1) {
      can = false;
    }
  }
  vector<vector<int>> backet(N, vector<int>(0));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (j + 1 == sc.at(i).at(0)) {
        backet.at(j).push_back(sc.at(i).at(1));
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == 0 && backet.at(i).size() == 0) {
      backet.at(i).push_back(1);
    } else if (backet.at(i).size() == 0) {
      backet.at(i).push_back(0);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j : backet.at(i)) {
      if (j != backet.at(i).at(0)) {
        can = false;
      }
    }
  }
  if (can) {
    for (int i = 0; i < N; i++) {
      cout << backet.at(i).at(0);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
