#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll mod(ll a) { return (a % 1000000007); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  vl num(n);
  for (ll i = 0; i < m; i++) {
    ll si, ci;
    cin >> si >> ci;
    si--;
    if ((num[si] != 0 && num[si] != ci) || ((n == 2 || n == 3) && ci == 0)) {
      ans = -1;
      break;
    } else
      num[si] = ci;
  }
  if ((n == 2 || n == 3) && num[0] == 0) num[0] = 1;
  if (ans)
    cout << ans << endl;
  else {
    for (ll a : num) cout << a;
    cout << endl;
  }
}
