#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
unsigned gcd(unsigned a, unsigned b) {
  if (a < b) return gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll pow_mod(ll num, ll pow, ll mod) {
  ll prod = 1;
  num %= mod;
  while (pow > 0) {
    if (pow & 1) prod = prod * num % mod;
    num = num * num % mod;
    pow >>= 1;
  }
  return prod;
}
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N, 0);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A.at(s) == 0 || A.at(s) == c)
      A.at(s) = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  int tmp = 100;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    ans += A.at(i) * tmp;
    tmp /= 10;
  }
  cout << ans << endl;
  return 0;
}
