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