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