#include <bits/stdc++.h>
using namespace std;
int cnt[30];
int32_t main() {
  long long int num, snum;
  cin >> num >> snum;
  long long int srr[num];
  for (long long int i = 0; i < num; i++) srr[i] = -1;
  while (snum--) {
    long long int hx, hy;
    cin >> hx >> hy;
    --hx;
    if (srr[hx] == -1)
      srr[hx] = hy;
    else {
      if (srr[hx] != hy) {
        cout << -1;
        return 0;
      }
    }
  }
  if (srr[num - 1] == -1)
    cout << -1;
  else {
    for (long long int i = 0; i < num; ++i) {
      if (srr[i] == -1)
        cout << 0;
      else
        cout << srr[i];
    }
  }
}
