#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> H;
  bool dame = 0;
  int max = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (H.count(s) && c != H[s])
      dame = 1;
    else
      H[s] = c;
  }
  if (dame || H[1] == 0)
    cout << -1 << endl;
  else {
    int sum = 0;
    if (H.count(1)) {
      for (int i = 1; i <= N; i++) sum += H[i] * pow(10, N - i);
    } else {
      for (int i = 1; i <= N; i++) sum += H[i] * pow(10, N - i);
      sum += pow(10, N - 1);
    }
    cout << sum << endl;
  }
}
