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