#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long binpow(long long x, long long k) {
  if (k == 0) {
    return 1LL;
  }
  long long temp = binpow(x, k / 2);
  if (k % 2 == 1) {
    return (((temp * temp) % mod) * x) % mod;
  } else {
    return (temp * temp) % mod;
  }
}
long long modular_inverse(long long x) { return binpow(x, mod - 2); }
long long binomial(long long n, long long k) {
  long long rez = 1;
  for (long long i = n - k + 1; i <= n; i++) {
    rez *= i;
    rez %= mod;
  }
  long long temp = 1;
  for (long long i = 1; i <= k; i++) {
    temp *= i;
    temp %= mod;
  }
  rez *= modular_inverse(temp);
  rez %= mod;
  return rez;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(3, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) {
      cout << "-1\n";
      return 0;
    } else {
      a[s - 1] = c;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) {
      if (i == 0) {
        if (n == 1) {
          cout << '0';
        } else {
          cout << '1';
        }
      } else {
        cout << '0';
      }
    } else {
      cout << a[i];
    }
  }
  cout << '\n';
  return 0;
}
