#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  int num[3] = {0};
  vector<bool> check(3, true);
  bool out = false;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (s == 1 && c == 0) out = true;
    if (check.at(n - s) || num[n - s] == c) {
      num[n - s] = c;
      check.at(n - s) = false;
    } else
      out = true;
  }
  if (!out)
    cout << 100 * num[2] + 10 * num[1] + num[0] << endl;
  else
    cout << -1 << endl;
}
