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