#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int LARGE_INT = 1e9 + 100;
const int INF = 2e9 + 100;
const long long INF_LL = (long long)INF * 300 * 300;
const int MOD = 1e9 + 7;
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a) {
  long long b = MOD, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}
long long moddev(long long a, long long b) { return a * modinv(b) % MOD; }
void Main() {
  int n, m;
  cin >> n >> m;
  vector<int> r(n, -1);
  for (int i = (0); i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (r[s] == -1) {
      r[s] = c;
    } else if (r[s] == c) {
    } else {
      cout << -1 << endl;
      return;
    }
  }
  if (r[0] == -1) {
    cout << -1 << endl;
    return;
  }
  if (n != 1 && r[0] == 0) {
    cout << -1 << endl;
    return;
  }
  for (int i = (0); i < (n); ++i) {
    if (i == 0 && r[i] == -1) {
      cout << 1;
    } else if (r[i] == -1) {
      cout << 0;
    } else {
      cout << r[i];
    }
  }
  cout << endl;
  return;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
