#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec = {0, 0, 0};
  for (int i = 0; i < M; i++) {
    int j, k;
    cin >> j >> k;
    if (k == 0 && j == 1) {
    } else if (vec.at(j - 1) == 0) {
      vec.at(j - 1) = k;
    } else {
      vec.at(j - 1) = min(vec.at(j - 1), k);
    }
  }
  for (int i = 0; i < 3; i++) {
    if (vec.at(i) == -1) {
      vec.at(i) = 0;
    }
  }
  if (N > 1 && vec.at(0) == 0) {
    cout << -1 << endl;
  } else if (N == 1) {
    cout << vec.at(0) << endl;
  } else if (N == 2) {
    cout << vec.at(0) * 10 + vec.at(1) << endl;
  } else if (N == 3) {
    cout << vec.at(0) * 100 + vec.at(1) * 10 + vec.at(2) << endl;
  } else {
    cout << 0 << endl;
  }
}
