#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int fail;
  fail = 0;
  map<int, int> answer;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) fail = 1;
    if (answer[s - 1] != 0 && answer[s - 1] != c) fail = 1;
    answer[s - 1] = c;
  }
  int total = 0;
  for (int i = 0; i < N; i++) {
    int biggest;
    biggest = 1;
    for (int j = 0; j < N - 1 - i; j++) biggest *= 10;
    total += biggest * answer[i];
  }
  if (fail == 1)
    cout << -1 << endl;
  else
    cout << total << endl;
}
