#include <bits/stdc++.h>
using namespace std;
long long int ar[4];
long long int done[4];
int32_t main() {
  long long int n, m, t, pos;
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++) {
    cin >> pos >> t;
    if (!done[pos] || ar[pos] == t) {
      done[pos] = 1;
      ar[pos] = t;
    } else {
      cout << -1;
      return 0;
    }
  }
  if (done[1] && !ar[1]) {
    cout << -1;
    return 0;
  }
  if (!done[1]) {
    ar[1] = 1;
  }
  for (long long int i = 1; i <= n; i++) {
    cout << ar[i];
  }
}
