#include <bits/stdc++.h>
using namespace std;
const int COMMAX = 510000;
long long fac[COMMAX], finv[COMMAX], inv[COMMAX];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcd(int a, int b) { return a * b / gcd(a, b); }
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N), rank(N) {
    num = N;
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    if (rank[rx] < rank[ry]) {
      par[rx] = ry;
    } else {
      par[ry] = rx;
      if (rank[rx] == rank[ry]) rank[rx]++;
    }
    num--;
  }
  bool same(int x, int y) { return root(x) == root(y); }
};
const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
  int n;
  vector<long long> hs[MS], pw[MS];
  rolling_hash() {}
  rolling_hash(const string &s) {
    n = s.size();
    for (int i = 0; i < MS; i++) {
      hs[i].assign(n + 1, 0);
      pw[i].assign(n + 1, 0);
      hs[i][0] = 0;
      pw[i][0] = 1;
      for (int j = 0; j < n; j++) {
        pw[i][j + 1] = pw[i][j] * base % mod[i];
        hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i];
      }
    }
  }
  long long hash(int l, int r, int i) {
    return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) % mod[i];
  }
  bool match(int l1, int r1, int l2, int r2) {
    bool ret = 1;
    for (int i = 0; i < MS; i++) ret &= hash(l1, r1, i) == hash(l2, r2, i);
    return ret;
  }
  bool match(int l, int r, long long h[]) {
    bool ret = 1;
    for (int i = 0; i < MS; i++) ret &= hash(l, r, i) == h[i];
    return ret;
  }
};
int hako[3];
int main() {
  int n, m;
  cin >> n >> m;
  hako[0] = hako[1] = hako[2] = -1;
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (hako[a] == -1 or hako[a] == b) {
      hako[a] = b;
    } else {
      flag = false;
    }
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  int res = hako[0] * 100 + hako[1] * 10 + hako[0];
  for (int i = 0; i < n - 1; i++)
    if (hako[1 - i] == 0) flag = false;
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  cout << res << endl;
  return 0;
}
