#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 228;
const long long INFLL = 1e18;
const long long MOD = 1e9 + 7;
const long double eps = 1e-6;
const long double eps2 = 1e-9;
const long long MOD2 = 998244353;
const long long dosz = 5e5;
const long long SZ = (1 << 18);
const long double PI = atan2l(0, -1);
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > lol(m);
  vector<long long> dig(n, -1);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    lol[i] = make_pair(a, b);
    dig[a] = b;
  }
  bool ok = true;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    a = lol[i].first;
    b = lol[i].second;
    if (dig[a] != b) {
      ok = false;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return;
  }
  bool used = false;
  for (long long i : dig) {
    if (i == -1) {
      if (used) {
        cout << 0;
      } else {
        cout << 1;
        used = true;
      }
    } else {
      cout << i;
      used = true;
    }
  }
}
signed main() {
  fast_io();
  srand(time(NULL));
  cout << fixed << setprecision(12);
  long long q = 1;
  while (q--) solve();
}
