#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  vector<long long> num(N, -1);
  for (int i = 0; i < M; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (num[s] == c || num[s] == -1) {
      num[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  long long res = 0;
  long long ba = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (num[i] == -1) num[i] = 0;
    res += ba * num[i];
    ba *= 10;
  }
  if (to_string(res).length() == N) {
    cout << res << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
