#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int m, n;
  cin >> n >> m;
  int a[n];
  int k, c;
  int ans = 0;
  for (int o = 0; o < n; o++) {
    a[o] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> k >> c;
    if (a[k - 1] != 0 && a[k - 1] != c) {
      ans = -1;
    } else {
      a[k - 1] = c;
    }
  }
  if (a[n - 1] == 0) {
    ans = -1;
  }
  if (ans != -1) {
    for (int j = 0; j < n; j++) {
      cout << a[j];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
