#include <bits/stdc++.h>
using namespace std;
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  int f[3] = {-1, -1, -1};
  bool flag = false;
  for (int i = 0; i < M; i++) {
    int a = f[(3 - N) + s[i] - 1];
    if (a == -1 || a == c[i]) {
      f[(3 - N) + s[i] - 1] = c[i];
    } else {
      flag = true;
      break;
    }
  }
  if (N == 3 && f[0] == 0) flag = true;
  if (N == 3 && f[1] == 0 && f[0] == -1) flag = true;
  if (N == 2 && f[1] == 0) flag = true;
  if (flag) {
    cout << -1 << endl;
    return;
  }
  bool top = true;
  for (int i = (3 - N); i < 3; i++) {
    if (f[i] != -1) {
      top = false;
    } else {
      if (top) {
        f[i] = 1;
        top = false;
      } else
        f[i] = 0;
    }
  }
  if (N == 1) f[2] = 0;
  int result = 0;
  int b = 100;
  for (int i = 0; i < 3; i++) {
    if (f[i] == -1) f[i] = 0;
    result += f[i] * b;
    b /= 10;
  }
  cout << result << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
