#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long mod = 1000000007;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, -1, 0, 1};
const long long NCK_MAX = 510000;
long long ketawa(long long n) {
  long long a = 0;
  while (n != 0) {
    a += n % 10;
    n /= 10;
  }
  return a;
}
long long RepeatSquaring(long long N, long long pair<long long, long long>,
                         long long M) {
  if (pair<long long, long long> == 0) return 1;
  if (pair<long long, long long> % 2 == 0) {
    long long t = RepeatSquaring(N, pair<long long, long long> / 2, M);
    return (t % M) * (t % M) % M;
  }
  return (N * RepeatSquaring(N, pair<long long, long long> - 1, M)) % M;
}
long long RS(long long N, long long pair<long long, long long>) {
  if (pair<long long, long long> == 0) return 1;
  if (pair<long long, long long> % 2 == 0) {
    long long t = RS(N, pair<long long, long long> / 2);
    return t * t;
  }
  return (N * RS(N, pair<long long, long long> - 1));
}
map<long long, int> prime_factor(long long n) {
  map<long long, int> ret;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
bool IsPrime(long long a) {
  if (a == 1) return false;
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0 && a != i) {
      return false;
    }
  }
  return true;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long extgcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long q = a / b, g = extgcd(b, a - q * b, x, y);
  long long z = x - q * y;
  x = y;
  y = z;
  return g;
}
long long invmod(long long a, long long m) {
  long long x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
long long *fac, *finv, *inv;
void nCk_init(long long mod) {
  fac = new long long[NCK_MAX];
  finv = new long long[NCK_MAX];
  inv = new long long[NCK_MAX];
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < NCK_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 nCk(long long n, long long k, long long mod) {
  if (fac == NULL) nCk_init(mod);
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long lmin(long long a, long long b) { return a > b ? b : a; };
long long lmax(long long a, long long b) { return a > b ? a : b; };
long long lsum(long long a, long long b) { return a + b; };
template <typename T>
class Zip {
  vector<T> d;
  bool flag;

 public:
  Zip() { flag = false; }
  void add(T x) {
    d.push_back(x);
    flag = true;
  }
  long long getNum(T x) {
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return lower_bound(d.begin(), d.end(), x) - d.begin();
  }
  long long size() {
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return (long long)d.size();
  }
};
class UnionFind {
  vector<long long> par, rank;

 public:
  void init(long long n) {
    par.resize(n, 1);
    rank.resize(n, 0);
  }
  long long getSize(long long x) { return par[find(x)]; }
  long long find(long long x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(long long x, long long y) { return find(x) == find(y); }
};
class SegmentTree {
 public:
  vector<pair<double, double>> node;
  long long n;
  pair<double, double> initial_value;

 public:
  void Init(long long n_, pair<double, double> initial_value_) {
    n = 1;
    while (n < n_) n *= 2;
    node.resize(2 * n);
    for (long long i = 0; i < 2 * n; i++) {
      node[i] = initial_value_;
    }
    initial_value = initial_value_;
  }
  void Update(long long k, pair<double, double> a) {
    k += n;
    node[k] = a;
    while (k > 1) {
      k = k / 2;
      node[k] = pair<double, double>(
          node[k * 2].first * node[k * 2 + 1].first,
          node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second);
    }
  }
  double Query() { return node[1].first + node[1].second; }
};
long long lis(long long* a, long long n, long long* dp) {
  fill(dp, dp + n, INF);
  for (long long i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i];
  return (long long)(lower_bound(dp, dp + n, INF) - dp);
}
long long n, m;
string s;
long long ans = 0;
vector<string> aa[10];
long long keta[3];
int main() {
  cin >> n >> m;
  keta[0] = -1;
  keta[1] = -1;
  keta[2] = -1;
  for (long long i = 0; i < m; i++) {
    long long ss;
    long long cc;
    cin >> ss >> cc;
    if (keta[ss - 1] != -1 && keta[ss - 1] != cc) {
      cout << -1 << endl;
      return 0;
    } else {
      keta[ss - 1] = cc;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (i == 0 && keta[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (i == 0 && keta[i] == -1) {
      if (n == 1) {
        cout << 0;
      } else {
        cout << 1;
      }
      continue;
    }
    if (keta[i] == -1) {
      cout << 0;
    } else {
      cout << keta[i];
    }
  }
  cout << endl;
}
