#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
bool is_prime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return 0;
  }
  return true;
}
vector<bool> prime_table(int n) {
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i]) continue;
    for (int j = i * i; j <= n; j++) prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
long long modpow(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(m);
  for (int i = 0; i < (m); i++) cin >> p[i].first >> p[i].second;
  sort((p).begin(), (p).end());
  int v = 1;
  for (int i = 0; i < (n - 1); i++) v *= 10;
  vector<bool> f(n);
  for (int i = 0; i < (m); i++) {
    if (f[p[i].first - 1] == 1) {
      if (p[i].second != p[i - 1].second) {
        cout << -1 << endl;
        return 0;
      }
      continue;
    }
    f[p[i].first - 1] = 1;
    int temp = 1;
    for (int j = 0; j < (n - p[i].first); j++) temp *= 10;
    if (p[i].first == 1)
      v += temp * (p[i].second - 1);
    else
      v += temp * p[i].second;
  }
  int border = 1;
  for (int i = 0; i < (n - 1); i++) border *= 10;
  if (n != 1 && v < border)
    cout << -1 << endl;
  else
    cout << v << endl;
  return 0;
}
