#include <bits/stdc++.h>
using namespace std;
using ldb = long double;
using pa = pair<long long, long long>;
const long long MOD = 1e9 + 7, N = 5e5 + 10;
const long long LINF = LLONG_MAX;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1];
  for (long long i = 0; i < n + 1; i++) {
    a[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    if (a[x] == -1 || a[x] == y) {
      a[x] = y;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[1] != -1 and a[n + 1] != -1) {
    for (long long i = 1; i < n + 1; i++) {
      if (a[i] == -1) {
        cout << 0;
      } else {
        cout << a[i];
      }
    }
  } else {
    cout << -1;
  }
  return 0;
}
