#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
  if (a < b) {
    NumType tmp = a;
    a = b;
    b = tmp;
  }
  NumType r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
template <typename NumType>
NumType cntDivisor(const NumType& num) {
  NumType cnt = 0;
  for (NumType i = 1; i * i <= num; ++i) {
    if (num % i == 0) {
      cnt++;
      if (i * i != num) cnt++;
    }
  }
  return cnt;
}
ll powMod(ll a, ll n, ll mod) {
  if (n == 0) return 1;
  if (n % 2 == 0)
    return powMod(a, n / 2, mod) * powMod(a, n / 2, mod) % mod;
  else
    return a * powMod(a, n - 1, mod) % mod;
}
ll ncrMod(ll n, ll r, ll mod) {
  ll x = 1, y = 1;
  for (ll i = 1; i <= r; ++i) {
    x *= n - i + 1;
    x %= mod;
    y *= i;
    y %= mod;
  }
  return x * powMod(y, mod - 2, mod) % mod;
}
int main() {
  int N, M;
  int s[5], c[5];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int min = (N == 1) ? 0 : pow(10, N - 1);
  int max = pow(10, N);
  for (int num = min; num < max; num++) {
    int keta[3];
    int num2 = num;
    for (int i = 0; i < 3; i++) {
      keta[2 - i] = (num2 == 0 && i > 0) ? -1 : num2 % 10;
      num2 /= 10;
    }
    int cnt = 0;
    for (int i = 0; i < M; i++) {
      if (keta[s[i] - 1] == c[i]) {
        cnt++;
      }
    }
    if (cnt == M) {
      cout << num;
      return 0;
    }
    if (num == max - 1) {
      cout << -1;
    }
  }
  return 0;
}
