#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
long long MOD = 1000000007;
long long modpow(long long a, long long p, long long mod) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    long long half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}
long long modCombination(long long n, long long a, long long mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }
  long long denominator = 1;
  long long numerator = 1;
  for (long long i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }
  return numerator * modpow(denominator, mod - 2, mod) % mod;
}
class UnionFind {
 private:
  vector<long long> parents;

 public:
  UnionFind(long long n) : parents(n, -1) {}
  bool issame(long long x, long long y) { return root(x) == root(y); }
  bool merge(long long x, long long y) {
    if (issame(x, y)) return false;
    long long rx = root(x);
    long long ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    parents[rx] += parents[ry];
    parents[ry] = rx;
    return true;
  }
  long long size(long long x) { return -parents[root(x)]; }

 private:
  long long root(long long x) {
    if (parents[x] < 0) return x;
    return parents[x] = root(parents[x]);
  }
};
int main() {
  cout << fixed << setprecision(15);
  long long N, M;
  cin >> N >> M;
  vector<long long> S(M);
  vector<long long> C(M);
  for (long long i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  vector<long long> digit(N, -1);
  long long ans = -1;
  long long ok = true;
  for (long long i = 0; i < M; i++) {
    long long index = S[i] - 1;
    if (digit[index] != -1 && digit[index] != C[i]) {
      ok = false;
      break;
    }
    digit[index] = C[i];
  }
  if (ok == true) {
    if (digit[0] == 0 && N != 1) {
      cout << "here" << endl;
      cout << -1 << endl;
    } else {
      if (digit[0] == -1) {
        if (N == 1) {
          digit[0] = 0;
        } else {
          digit[0] = 1;
        }
      }
      for (long long i = 0; i < N; i++) {
        if (digit[i] == -1) {
          digit[i] = 0;
        }
      }
      long long ans = 0;
      for (auto d : digit) {
        ans = 10 * ans + d;
      }
      cout << ans << endl;
    }
  } else {
    cout << "here1" << endl;
    cout << -1 << endl;
  }
  return 0;
}
