#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  vector<int> ans(N, -1);
  for (int j = 0; j < M; j++) {
    if (ans[s[j] - 1] == -1 || ans[s[j] - 1] == c[j]) {
      ans[s[j] - 1] = c[j];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << (ans[0] == -1 ? 1 : ans[0]);
  for (int i = 1; i < N; i++) {
    cout << (ans[i] == -1 ? 0 : ans[i]);
  }
  cout << endl;
  return 0;
}
