#include <bits/stdc++.h>
using namespace std;
struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;
  ProconInit() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(IOS_PREC);
    if (AUTOFLUSH) cout << unitbuf;
  }
} PROCON_INIT;
long long MOD = 1000000007;
int digit_length(int num) {
  int count = 0;
  while (num) {
    num = num / 10;
    ++count;
  }
  return count;
}
long long gcd(long long a, long long b) {
  long long v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long lcm(long long a, long long b) {
  return ((a % MOD) * modinv(gcd(a, b), MOD) * (b % MOD)) % MOD;
}
void solve() {
  int S[10];
  int C[10];
  int N, M;
  string out = "000";
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> S[i];
    cin >> C[i];
  }
  bool match = false;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == S[j] && C[i] != C[j]) {
        cout << -1;
        return;
      }
      if (1 == S[j] && 0 == C[j]) {
        cout << -1;
        return;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    out.at(S[i] - 1 + (3 - N)) = '0' + C[i];
  }
  if (N == 3 && out.at(0) == '0') {
    out.at(0) = '1';
  }
  if (N == 2 && out.at(1) == '0') {
    out.at(1) = '1';
  }
  if (N == 1 && out.at(2) == '0') {
    out.at(2) = '1';
  }
  int num = atoi(out.c_str());
  match = true;
  if (match) {
    cout << num;
  } else {
    cout << -1;
  }
  return;
}
int main() {
  solve();
  return 0;
}
