#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N, 10);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (vec.at(s - 1) == 10 || vec.at(s - 1) == c)
      vec.at(s - 1) = c;
    else {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int j = 0; j < N; j++) {
    if (vec.at(j) == 10) {
      cout << 0;
    } else
      cout << vec.at(j);
  }
  return 0;
}
