#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  int N, M, si, ci;
  cin >> N;
  if (N > 3) {
    cout << -1 << endl;
    ;
    exit(0);
  }
  cin >> M;
  string str;
  vector<int> sint;
  vector<int> cint;
  vector<int> vb;
  for (int i = 0; i < N; i++) {
    str += "0";
    vb.push_back(-1);
  }
  for (int i = 0; i < M; i++) {
    cin >> si >> ci;
    sint.push_back(si);
    cint.push_back(ci);
  }
  for (int i = 0; i < M; i++) {
    str.at(sint.at(i) - 1) = ('0' + cint.at(i));
    if (vb.at(sint.at(i) - 1) != -1) {
      if (vb.at(sint.at(i) - 1) != cint.at(i)) {
        cout << -1 << endl;
        ;
        exit(0);
      }
    }
    vb.at(sint.at(i) - 1) = cint.at(i);
  }
  if (str == "000" || str == "00") {
    if (M == 0) {
      str.at(0) = '1';
    } else {
      cout << -1 << endl;
      ;
      exit(0);
    }
  }
  while (str.at(0) == 0) {
    str.erase(0, 1);
  }
  cout << str << endl;
  ;
}
