#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, a, b, t = 0;
  cin >> n >> m;
  int ar[5];
  memset(ar, -1, sizeof(ar));
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    if (ar[a] == -1 || ar[a] == b)
      ar[a] = b;
    else {
      t = 1;
    }
  }
  if (t == 0 && ar[1] != 0) {
    for (i = 1; i <= n; i++) {
      if (ar[i] == -1)
        cout << 0;
      else
        cout << ar[i];
    }
  } else
    cout << -1;
}
