#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int MOD = 1000000007;
void sort_second(vector<pair<long long, long long>> &A, int N);
long long a_n(long long a, long long n);
void factorial_map(vector<long long> &n, vector<long long> &ninv);
long long inv(long long a);
void prime_map(map<int, int> &a, int n);
void prime_list(int n, vector<int> &primes, vector<bool> &is_prime);
long long gcd_map(map<int, int> a, map<int, int> b);
long long lcm_map(map<int, int> a, map<int, int> b);
long long my_gcd(long long a, long long b);
long long nCk(long long n, long long k);
int main() {
  int n, m, ret = 0, max_s = 0;
  map<int, int> a;
  cin >> n >> m;
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    int s, c;
    cin >> s >> c;
    if (a.count(s) && a.at(s) != c) {
      cout << -1 << endl;
      return 0;
    }
    if (!a.count(s)) a[s] = c;
  }
  if (n > 1 && a.count(1) && a.at(1) == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (auto p : a) {
    auto key = p.first;
    auto value = p.second;
    ret += a_n(10, n - key) * value;
  }
  if (!a.count(1)) ret += a_n(10, n - 1);
  cout << ret << endl;
  return 0;
}
void sort_second(vector<pair<long long, long long>> &A, int N) {
  for (int(i) = 0; (i) < (int)(N); (i)++) swap(A.at(i).first, A.at(i).second);
  sort((A).begin(), (A).end());
  for (int(i) = 0; (i) < (int)(N); (i)++) swap(A.at(i).first, A.at(i).second);
}
long long a_n(long long a, long long n) {
  if (n == 0) return 1;
  long long ret = a, count = 1;
  while (count * 2 < n) {
    ret *= ret;
    ret %= MOD;
    count *= 2;
  }
  if (count == n)
    return ret;
  else
    return (ret * a_n(a, n - count)) % MOD;
}
void factorial_map(vector<long long> &n, vector<long long> &ninv) {
  n[0] = 1;
  for (int i = 1; i < n.size(); i++) n[i] = (n[i - 1] * i) % MOD;
  ninv[n.size() - 1] = inv(n[n.size() - 1]);
  for (int i = n.size() - 2; i > -1; i--)
    ninv[i] = (ninv[i + 1] * (i + 1)) % MOD;
}
long long inv(long long a) { return a_n(a, MOD - 2); }
void prime_map(map<int, int> &a, int n) {
  while ((n % 2) == 0) {
    n /= 2;
    if (a.count(2))
      a.at(2)++;
    else
      a[2] = 1;
  }
  for (int i = 3; i * i <= n; i += 2) {
    while ((n % i) == 0) {
      n /= i;
      if (a.count(i))
        a.at(i)++;
      else
        a[i] = 1;
    }
  }
  if (n != 1) a[n] = 1;
}
long long gcd_map(map<int, int> a, map<int, int> b) {
  long long ret = 1;
  for (auto p : a) {
    auto key = p.first;
    auto value = p.second;
    if (b.count(key)) {
      if (value > b.at(key))
        ret *= a_n(key, b.at(key));
      else
        ret *= a_n(key, value);
    }
  }
  return ret;
}
long long lcm_map(map<int, int> a, map<int, int> b) {
  long long ret = 1;
  for (auto p : a) {
    auto key = p.first;
    auto value = p.second;
    if (b.count(key)) {
      if (value > b.at(key))
        ret *= a_n(key, value);
      else
        ret *= a_n(key, b.at(key));
    } else {
      ret *= a_n(key, value);
    }
  }
  for (auto p : b) {
    auto key = p.first;
    auto value = p.second;
    if (a.count(key)) {
      continue;
    } else {
      ret *= a_n(key, value);
    }
  }
  return ret;
}
long long my_gcd(long long a, long long b) {
  if (b == 0) return a;
  return my_gcd(b, a % b);
}
long long nCk(long long n, long long k) {
  long long kfac = 1, ret = 1;
  for (int i = 1; i <= k; i++) {
    kfac = (kfac * i) % MOD;
  }
  for (int i = n; i >= n - k + 1; i--) {
    ret = (ret * i) % MOD;
  }
  ret = (ret * inv(kfac)) % MOD;
  return ret;
}
void prime_list(int n, vector<int> &primes, vector<bool> &is_prime) {
  int p = 0;
  for (int(i) = 0; (i) < (int)(n + 1); (i)++) is_prime[i] = true;
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
  }
}
