#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 + 3 - n] != -1 && x[a - 1 + 3 - n] != b) {
      z = false;
    } else
      x[a - 1 + 3 - n] = b;
  }
  for (int i = 0; i < 3; i++) {
    if (x[i] == -1) x[i] = 0;
  }
  if (z) {
    if (x[0] != 0)
      cout << x[0] * 100 + x[1] * 10 + x[2] << endl;
    else if (n == 3)
      cout << 100 + x[1] * 10 + x[2] << endl;
    else if (n == 2)
      cout << 10 + x[2] << endl;
    else
      cout << x[2] << endl;
  } else
    cout << -1 << endl;
  return 0;
}
