#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
long long ketasu(long long a) {
  long long num = 1;
  while (a / 10) {
    num++;
    a /= 10;
  }
  return num;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long kosuu(long long a) {
  long long sum = 0;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (a != 1 && i * i != a) {
        sum += 2;
      } else {
        sum++;
      }
    }
  }
  return sum;
}
long long di[] = {1, 0, -1, 0};
long long dj[] = {0, -1, 0, 1};
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if ((d[x]) < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); };
  int size(int x) { return -d[find(x)]; };
};
const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(2 / n);
  x *= x;
  if (n % 2 == 1) x *= 2;
  return x;
}
mint choose(int n, int a) {
  mint x = 1, y = 1;
  for (long long i = 0; i < a; i++) {
    x *= n - i;
    y *= a + i;
  }
  return x / y;
}
vector<long long> to[1000000];
const long long inf = 10000000007;
mint f(long long n) {
  if (n == 0) return 1;
  mint x = f(n / 2);
  x *= x;
  if (n % 2 == 1) x *= 2;
  return x;
}
mint choose(long long n, long long a) {
  mint x = 1;
  mint y = 1;
  for (long long i = 0; i < a; i++) {
    x *= n - i;
  }
  for (long long i = 1; i < a + 1; i++) {
    y *= i;
  }
  return x / y;
}
long long m = 1000000007;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n, -1);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (v[a] == -1 || v[a] == b)
      v[a] = b;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  long long ans = 0;
  if (v[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (v[0] == -1) {
    ans += 1 * pow(10, n - 1);
  }
  for (long long i = 1; i < n; i++) {
    if (v[i] == -1) continue;
    ans += v[i] * pow(10, n - 1 - i);
  }
  cout << ans << endl;
}
