#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using ld = long double;
const ll mod = (ll)1e9 + 7;
const ll mxN = (ll)4e5 + 3;
void solve() {
  ll n, m;
  cin >> n >> m;
  vll A(n, -1);
  if (n == 1) {
    A[0] = 0;
  }
  bool ok = true;
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    if (n != 0 && x == 1 && y == 0)
      ok = false;
    else if (A[x - 1] == -1)
      A[x - 1] = y;
    else if (A[x - 1] == y)
      continue;
    else
      ok = false;
  }
  if (ok)
    for (auto i : A)
      if (i == -1)
        cout << 0;
      else
        cout << i;
  else
    cout << -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(20);
  cout << fixed;
  solve();
}
