#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;
const ll mod = ll(1e9) + 7;
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll factorial(ll n) {
  ll t = 1;
  for (ll(i) = 1; (i) <= (n); ++(i)) {
    t *= i;
    t %= mod;
  }
  return t;
}
ll power(ll a, ll b) {
  a %= mod;
  if (b == 0) {
    return 1;
  }
  ll ans = power(a, b / 2);
  ans = ans * ans % mod;
  if (b % 2 == 1) {
    ans = ans * a % mod;
  }
  return ans;
}
ll combination(ll a, ll b) {
  if ((a == b) || (b == 0)) {
    return 1;
  }
  if (a < b) return 0;
  ll ans = 1;
  for (ll i = 0; i < b; i++) {
    ans *= (a - i);
    ans %= mod;
    ans *= power(i + 1, mod - 2);
    ans %= mod;
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, 0);
  vector<pair<int, int>> sc(m);
  ans[0] = 0;
  for (ll(i) = 0; (i) < (m); ++(i)) {
    int s, c;
    cin >> s >> c;
    sc[i] = make_pair(s, c);
  }
  sort((sc).begin(), (sc).end());
  for (ll(i) = 0; (i) < (m); ++(i)) {
    if ((sc[i].first == sc[i + 1].first && sc[i].second != sc[i + 1].second) ||
        (sc[i].first == 1 && n != 0 && sc[i].second == 0) ||
        (sc[i].first > n)) {
      cout << (-1) << endl;
      return 0;
    }
    ans[sc[i].first - 1] = sc[i].second;
  }
  if (n != 0 && ans[0] == 0) ans[0] = 1;
  for (ll(i) = 0; (i) < (n); ++(i)) cout << ans[i];
  cout << ("") << endl;
  return 0;
}
