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