#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a;
  int e[3];
  for (int i = 0; i < a; i++) e[i] = 0;
  cin >> b;
  for (int j = 0; j < b; j++) {
    cin >> c >> d;
    if (e[c - 1] != 0 && e[c - 1] != d) {
      cout << "-1" << endl;
      return 0;
    }
    e[c - 1] = d;
  }
  if (e[0] != 0)
    cout << e[0] << e[1] << e[2] << endl;
  else if (e[1] != 0)
    cout << e[0] << e[1] << endl;
  else if (e[0] != 0)
    cout << e[0] << endl;
  else
    cout << "-1" << endl;
}
