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