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