#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0;
  cin >> n >> m;
  int a[n], i, p, x;
  for (i = 0; i < n; i++) {
    a[i] = 0;
  }
  while (m--) {
    cin >> p >> x;
    if (a[p - 1] != 0) {
      if (a[p - 1] != x) {
        f = 1;
      }
    } else
      a[p - 1] = x;
  }
  if (a[0] == 0) f = 1;
  if (f == 1)
    cout << -1 << endl;
  else {
    for (i = 0; i < n; i++) cout << a[i];
  }
}
