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