#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  set<pair<int, int>> S;
  for (int i = 0; i < (int)(M); i++) {
    pair<int, int> p;
    cin >> p.first >> p.second;
    S.insert(p);
  }
  string num = "000";
  vector<bool> judge = {true, true, true};
  for (auto x : S) {
    if (judge.at(x.first - 1) == true) {
      judge.at(x.first - 1) = false;
      num.at(x.first - 1) = x.second + 48;
    } else {
      puts("-1");
      return 0;
    }
  }
  if (num.at(0) == 0 && (judge.at(1) == false || judge.at(2) == false))
    puts("-1");
  else
    cout << stoi(num) << endl;
  return 0;
}
