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