#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, t, m, a[10], b[10], q = 1, w = 1, e = 1;
  cin >> n >> m;
  if (n == 1 && m == 0) {
    cout << 0;
    return 0;
  }
  if (n != 1 && m == 0) {
    cout << -1;
    return 0;
  }
  for (i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    if (b[i] == 0 && a[i] == 1 && n > 1) {
      cout << -1;
      return 0;
    }
    if (n == 1 && a[i] == 1 && b[i] == 0) {
      cout << 0;
      return 0;
    }
  }
  for (j = 1; j <= m; j++) {
    for (i = j + 1; i <= m; i++) {
      if (i != j && a[j] == a[i] && b[j] != b[i]) {
        cout << -1;
        return 0;
      }
    }
  }
  if (n == 3) {
    for (i = 1; i <= m; i++) {
      if (a[i] == 1) {
        q = 0;
        cout << b[i];
        break;
      }
    }
    if (q) cout << 1;
    for (i = 1; i <= m; i++) {
      if (a[i] == 2) {
        cout << b[i];
        w = 0;
        break;
      }
    }
    if (w) cout << 0;
    for (i = 1; i <= m; i++) {
      if (a[i] == 3) {
        cout << b[i];
        e = 0;
        break;
      }
    }
    if (e) cout << 0;
  } else if (n == 2) {
    for (i = 1; i <= m; i++) {
      if (a[i] == 1) {
        q = 0;
        cout << b[i];
        break;
      }
    }
    if (q) cout << 1;
    for (i = 1; i <= m; i++) {
      if (a[i] == 2) {
        cout << b[i];
        w = 0;
        break;
      }
    }
    if (w) cout << 0;
  } else {
    for (i = 1; i <= m; i++) {
      if (a[i] == 1) {
        q = 0;
        cout << b[i];
        break;
      }
    }
    if (q) cout << 1;
  }
}
