#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> v(n + 5);
  ll x, y;
  for (ll i = 0; i < m; i++) {
    cin >> x >> y;
    if (v[x] != 0) {
      if (v[x] != y) {
        cout << "-1\n";
        return 0;
      }
    } else {
      v[x] = y;
    }
  }
  ll cnt = 0;
  for (ll i = 1; i <= n; i++) {
    if (v[i] == 0) {
      cnt++;
    }
  }
  if (cnt == n && n > 1) {
    cout << "-1\n";
    return 0;
  }
  for (ll i = 1; i <= n; i++) {
    cout << v[i];
  }
  return 0;
}
