#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[4] = {0};
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] != 0) {
      if (a[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      a[s] = c;
    }
  }
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum = a[i] + sum * 10;
  }
  int keta = 0;
  for (int check = sum; check > 0; check /= 10) keta++;
  if (keta == N)
    cout << sum << endl;
  else
    cout << -1 << endl;
  return 0;
}
