#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> s(M), c(M);
  for (int64_t i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int64_t> order(N + 1, -1);
  for (int64_t i = 0; i < M; i++) {
    if (order[s[i]] != -1 && order[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    order[s[i]] = c[i];
  }
  if (N > 1 && order[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int64_t i = 1; i <= N; i++) {
    cout << (order[i] == -1 ? (i == 1 ? 1 : 0) : order[i]);
  }
  cout << endl;
}
