#include <bits/stdc++.h>
using namespace std;
using vll = vector<long long>;
using vi = vector<int>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
long long llpow(T x, T n) {
  long long ans = 1;
  if (x == 0) ans = 0;
  while (n) {
    if (n & 1) ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
template <class T>
inline T gcd(T x, T y) {
  if (y == 0)
    return x;
  else {
    return gcd(y, x % y);
  }
}
template <class T>
inline T lcm(T x, T y) {
  return x / gcd(x, y) * y;
}
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;
}
long long INF = 1LL << 60;
int main() {
  long long n, m;
  cin >> n >> m;
  vll s(m), c(m);
  for (long long i = 0; i < (long long)m; i++) cin >> s[i] >> c[i];
  vi ans(n, -1);
  for (long long i = 0; i < (long long)m; i++) {
    if (ans[s[i] - 1] == -1) {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] == c[i])
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
    if (ans[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[0] == -1) {
      bool check = true;
      for (long long i = 0; i < (long long)n; i++)
        if (ans[i] != 0) check = false;
      if (check) {
        cout << -1;
        return 0;
      }
      ans[0] = 1;
    }
  }
  for (long long i = 0; i < (long long)n; i++) {
    if (ans[i] != -1)
      cout << ans[i];
    else {
      cout << 0;
    }
  }
}
