#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[11] = {0}, l, r, k = 0;
  cin >> n >> m;
  int ok = 1;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    if (l == 1 && r == 0) r--;
    if (a[l] && a[l] != r)
      ok = 0;
    else
      a[l] = r;
    k = max(k, l);
  }
  if ((a[1] == -1 && n != 1) || k > n) ok = 0;
  if (ok) {
    for (int i = 1; i <= n; i++) {
      cout << a[i];
    }
  } else
    cout << -1;
  cout << endl;
  return 0;
}
