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