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