#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000;
const long long MOD = 1000000007;
long long fac[MAX];
long long pow_kai(long long a, long long n) {
  long long x = 1;
  while (n > 0) {
    if (n & 1) {
      x = x * a % MOD;
    }
    a = a * a % MOD;
    n >>= 1;
  }
  return x;
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  long long tmp = 1;
  for (long long i = n; i >= n - k + 1; i--) tmp = (tmp * i) % MOD;
  return (tmp * pow_kai(fac[k], MOD - 2)) % MOD;
}
int main() {
  long long N, M, ans = -100;
  cin >> N >> M;
  long long dig[N];
  for (int i = 0; i < N; i++) dig[i] = -100;
  long long s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s = s - 1;
    if (dig[s] != -100 && dig[s] != c) {
      ans = -1;
      cout << ans << endl;
      return 0;
    } else {
      dig[s] = c;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      if (dig[i] == -100) {
        dig[i] = 1;
      }
    } else {
      if (dig[i] == -100) {
        dig[i] = 0;
      }
    }
  }
  if (ans != -1) {
    ans = 0;
    for (int i = 0; i < N; i++) {
      ans += dig[i] * pow_kai(10, N - 1 - i);
    }
  }
  if (dig[0] == 0) {
    ans = -1;
  }
  if (dig[0] == 0 && N == 1) {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}
