#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, x, y;
  cin >> n >> m;
  int ara[n + 1];
  for (i = 1; i <= n; i++) {
    ara[i] = -1;
  }
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    if (ara[x] == -1 || ara[x] == y) {
      ara[x] = y;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if ((ara[1] == -1 || ara[1] == 0) && n >= 2) {
    cout << -1 << endl;
  } else {
    for (i = 1; i <= n; i++) {
      cout << max(ara[i], 0);
    }
    cout << endl;
  }
  return 0;
}
