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