#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
map<T, T> getPrimeFactor(T n) {
  map<T, T> res;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}
template <typename T>
bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
ll pow2(ll n, ll p, ll mod) {
  if (p == 0 || n == 1) {
    return 1;
  } else {
    ll ret = pow2(n * n % mod, p / 2, mod);
    if (p % 2 == 1) {
      ret *= n;
    }
    return ret % mod;
  }
}
int main() {
  ll N, M, s;
  char c;
  std::cin >> N >> M;
  map<ll, char> dic;
  map<ll, bool> flg;
  for (ll i = 0; i < M; i++) {
    std::cin >> s >> c;
    if (flg[s] && dic[s] != c) {
      std::cout << -1 << endl;
      return 0;
    }
    flg[s] = true;
    dic[s] = c;
  }
  if (N > 1 && flg[1] && dic[1] == 0) {
    std::cout << -1 << endl;
    return 0;
  } else if (!flg[1]) {
    dic[1] = '1';
  }
  ll cnt = 0;
  string str = "";
  for (auto itr = dic.begin(); itr != dic.end(); itr++) {
    if (itr->first - cnt > 1) {
      str += string(itr->first - cnt - 1, '0');
    }
    cnt = itr->first;
    str += itr->second;
  }
  if (str.size() == N) {
    std::cout << str << endl;
  } else {
    std::cout << -1 << endl;
  }
  return 0;
}
