#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = {0, -1, 1, 0};
const ll dy[4] = {-1, 0, 0, 1};
const int INF = 1e9 + 7;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  return gcd(y, x % y);
}
void mul(ll a, ll b) { a = a * b % INF; }
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
  if (n == 0) {
    return 1;
  }
  if (n % 2 == 0) {
    return mypow(x * x % m, n / 2, m);
  } else {
    return x * mypow(x, n - 1, m) % m;
  }
}
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;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; ++i) {
    fac[i] = fac[i - 1] * i % INF;
    inv[i] = INF - inv[INF % i] * (INF / i) % INF;
    finv[i] = finv[i - 1] * inv[i] % INF;
  }
}
ll 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] % INF) % INF;
}
int main() {
  int n, m;
  cin >> n >> m;
  int key[3];
  for (ll i = (0); i <= (3 - 1); i++) key[i] = -1;
  for (ll i = (0); i <= (m - 1); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (key[s] == -1) {
      key[s] = c;
    } else {
      if (key[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n != 1) {
    if (key[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (ll i = (0); i <= (n - 1); i++) {
    if (i == 0) {
      if (key[i] == -1) {
        cout << 1;
      } else {
        cout << key[i];
      }
    } else {
      if (key[i] == -1) {
        cout << 0;
      } else {
        cout << key[i];
      }
    }
  }
  cout << endl;
  return 0;
}
