#include <bits/stdc++.h>
void Init() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  struct Init_caller {
    Init_caller() { Init(); }
  } caller;
}
using namespace std;
using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mii = map<LL, LL>;
using mpii = map<pi, LL>;
using mib = map<LL, bool>;
using mci = map<char, LL>;
using msb = map<st, bool>;
using vpi = vector<pi>;
using vppi = vector<ppi>;
using spi = stack<pi>;
using qpi = queue<pi>;
LL dx[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
LL dy[] = {0, 1, -1, 0, 1, -1, 1, -1, 0};
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (LL(i) = 0; (i) < (v.size()); (i)++) {
    in >> v[i];
  }
  return in;
}
template <typename T, typename U>
istream &operator>>(istream &in, pair<T, U> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
  out << "{";
  for (LL(i) = 0; (i) < (v.size()); (i)++) {
    out << v[i] << ",";
  }
  out << "}"
      << "\n";
  return out;
}
template <typename T, typename U>
ostream &operator<<(ostream &out, pair<T, U> &p) {
  out << "{" << p.first << "," << p.second << "}"
      << "\n";
  return out;
}
struct mint {
  LL x;
  mint(LL x = 0)
      : x((x % (1000000000 + 7) + (1000000000 + 7)) % (1000000000 + 7)) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= (1000000000 + 7)) x -= (1000000000 + 7);
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += (1000000000 + 7) - a.x) >= (1000000000 + 7))
      x -= (1000000000 + 7);
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= (1000000000 + 7);
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(LL 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((1000000000 + 7) - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
void y_n(bool p) {
  p ? cout << "Yes"
           << "\n"
    : cout << "No"
           << "\n";
}
void Y_N(bool p) {
  p ? cout << "YES"
           << "\n"
    : cout << "NO"
           << "\n";
}
template <typename T>
pair<pair<T, LL>, pair<T, LL>> vmaxmin(vector<T> v) {
  LL n = v.size();
  LL MAX = -LLONG_MAX;
  LL MIN = LLONG_MAX;
  LL maxpos = 0;
  LL minpos = 0;
  for (LL(i) = 0; (i) < (n); (i)++) {
    if (MAX < v[i]) {
      maxpos = i;
      MAX = v[i];
    }
    if (MIN > v[i]) {
      minpos = i;
      MIN = v[i];
    }
  }
  return {{MAX, maxpos}, {MIN, minpos}};
}
template <typename T>
T vsum(vector<T> v) {
  LL n = v.size();
  T sum = 0;
  for (LL(i) = 0; (i) < (n); (i)++) {
    sum += v[i];
  }
  return sum;
}
LL gcd(LL a, LL b) {
  if (b == 0) {
    swap(a, b);
  }
  LL r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}
LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); }
bool is_square(LL n) {
  if ((LL)sqrt(n) * (LL)sqrt(n) == n) {
    return true;
  } else {
    return false;
  }
}
bool is_prime(LL n) {
  if (n <= 1) {
    return true;
  } else {
    for (LL i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        return false;
      }
    }
  }
  return true;
}
void dec_num(LL n, vi &v) {
  LL a = 2;
  v.push_back(1);
  v.push_back(n);
  while (a * a <= n) {
    if (n % a == 0) {
      v.push_back(a);
      v.push_back(n / a);
    }
    a++;
  }
  sort((v).begin(), (v).end());
}
void dec_prime(LL n, vi &v) {
  LL a = 2;
  while (a * a <= n) {
    if (n % a == 0) {
      v.push_back(a);
      n /= a;
    } else {
      a++;
    }
  }
  v.push_back(n);
}
void dec_prime_e(LL n, map<LL, LL> &m) {
  for (LL i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      LL e = 0;
      while (n % i == 0) {
        e++;
        n /= i;
      }
      m[i] += e;
    }
  }
  if (n != 1) m[n]++;
}
LL sieve_prime(LL a, LL b) {
  if (a > b) swap(a, b);
  vb s(b + 1, true);
  LL cnt_a = 0, cnt_b = 0;
  for (LL i = 2; i <= b; i++) {
    for (LL j = 2; i * j <= b; j++) {
      s[i * j] = false;
    }
  }
  for (LL i = 2; i <= b; i++) {
    if (s[i]) {
      if (i < a) {
        cnt_a++;
      }
      cnt_b++;
    }
  }
  return cnt_b - cnt_a;
}
LL factorial(LL n) {
  LL a = 1, ret = 1;
  while (a < n) {
    a++;
    ret *= a;
  }
  return ret;
}
LL bit_count(LL n) {
  LL k = (LL)log2(n) + 1;
  LL ret = 0;
  for (LL(i) = 0; (i) < (k); (i)++) {
    if (n & (1LL << i)) ret++;
  }
  return ret;
}
const LL COMBMAX = 4000;
LL comb[COMBMAX + 5][COMBMAX + 5];
void init_comb() {
  comb[0][0] = 1;
  for (LL(i) = 0; (i) < (COMBMAX); (i)++) {
    for (LL(j) = 0; (j) < (i + 1); (j)++) {
      comb[i + 1][j] += comb[i][j];
      comb[i + 1][j] %= (1000000000 + 7);
      comb[i + 1][j + 1] += comb[i][j];
      comb[i + 1][j + 1] %= (1000000000 + 7);
    }
  }
}
LL combination(LL n, LL k) {
  if (k < 0 || k > n)
    return 0;
  else
    return comb[n][k];
}
const LL COMBMODMAX = 5000000;
LL fac[COMBMODMAX + 5], facinv[COMBMODMAX + 5], inv[COMBMODMAX + 5];
void init_comb_mod() {
  fac[0] = fac[1] = 1;
  facinv[0] = facinv[1] = 1;
  inv[1] = 1;
  for (LL i = 2; i < COMBMODMAX; i++) {
    fac[i] = fac[i - 1] * i % (1000000000 + 7);
    inv[i] = (1000000000 + 7) - inv[(1000000000 + 7) % i] *
                                    ((1000000000 + 7) / i) % (1000000000 + 7);
    facinv[i] = facinv[i - 1] * inv[i] % (1000000000 + 7);
  }
}
LL comb_mod(LL n, LL k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (facinv[k] * facinv[n - k] % (1000000000 + 7)) %
         (1000000000 + 7);
}
LL pow_mod(LL x, LL n, LL p) {
  if (n == 0) return 1;
  LL res = pow_mod(x * x % p, n / 2, p);
  if (n % 2 == 1) res = res * x % p;
  return res;
}
struct edge {
  LL to;
  LL cost;
};
using ve = vector<edge>;
using vve = vector<ve>;
signed main() {
  LL n, m;
  cin >> n >> m;
  vi s(m), c(m);
  for (LL(i) = 0; (i) < (m); (i)++) {
    cin >> s[i] >> c[i];
  }
  vi ans(n, -1);
  for (LL(i) = 0; (i) < (m); (i)++) {
    if (ans[s[i] - 1] == -1 || ans[s[i] - 1] == c[i])
      ans[s[i] - 1] = c[i];
    else {
      cout << -1;
      return 0;
    }
  }
  if (ans[0] == 0) {
    cout << -1;
  } else {
    for (LL(i) = 0; (i) < (n); (i)++) {
      if (ans[i] == -1) {
        if (n > 1 && i == 0)
          cout << 1;
        else
          cout << 0;
      } else {
        cout << ans[i];
      }
    }
  }
}
