#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll N, M;
  cin >> N >> M;
  map<ll, ll> m;
  for (int(i) = 0; (i) < (M); (i)++) {
    ll tmp, tmp2;
    cin >> tmp >> tmp2;
    if (m[tmp] != 0 && m[tmp] != tmp2) {
      cout << -1 << endl;
      exit(0);
    } else {
      m[tmp] = tmp2;
    }
  }
  if (N != 1) {
    if (m[1] == 0 || (N == 1 && m[2] != 0 && m[3] != 0) ||
        (N == 2 && m[3] != 0)) {
      cout << -1 << endl;
      exit(0);
    }
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    cout << m[i + 1];
  }
  cout << endl;
}
