#include <bits/stdc++.h>
using namespace std;
int main() {
  int kinshi = 0;
  int N, M;
  cin >> N >> M;
  vector<int> keta(N, 0);
  vector<int> ketakanri(N, 0);
  keta[0] = 1;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ketakanri[s]) {
      if (keta[s] != c) {
        kinshi++;
      }
    }
    keta[s] = c;
    ketakanri[s] = 1;
  }
  if (N != 1) {
    if (keta[0] == 0) kinshi++;
  }
  if (kinshi)
    cout << -1;
  else {
    for (int i = 0; i < (int)(N); i++) cout << keta[i];
  }
}
