#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> nb(N);
  vector<int> nt(N);
  for (int i = 0; i < M; i++) {
    int si, ci;
    cin >> si >> ci;
    if (N > 1 && si == 1 && ci == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (nb.at(N - si) && nt.at(N - si) != ci) {
      cout << -1 << endl;
      return 0;
    }
    nb.at(N - si) = true;
    nt.at(N - si) = ci;
  }
  for (int i = N - 1; i > -1; i--) {
    if (nb.at(i))
      cout << nt.at(i);
    else
      cout << 0;
  }
  cout << endl;
}
