#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> vec(n, -1);
  for (int _ = 0; _ < (m); _++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (vec[s] >= 0 and vec[s] != c) {
      printf("-1");
      return 0;
    }
    vec[s] = c;
  }
  if (vec[0] == 0) {
    printf("-1");
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    printf("%d", vec[i] >= 0 ? vec[i] : 0);
  }
}
