#include <bits/stdc++.h>
using namespace std;
static const int INF = INT_MAX;
static const long long LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const long long LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
long long fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < SIZE; ++i) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = (finv[i - 1] * inv[i]) % MOD;
  }
}
long long comb(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
vector<int> Div(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a[SIZE];
  for (int i = 0; i < SIZE; ++i) a[i] = -1;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << '\n';
      return 0;
    }
    if (a[s] != -1 && a[s] != c) {
      cout << -1 << '\n';
      return 0;
    }
    a[s] = c;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] == -1) {
      if (i == 1)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << a[i];
    }
  }
  cout << '\n';
  return 0;
}
