#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M, sbuf, cbuf;
  vector<pair<int, int>> sc;
  vector<int> power10 = {1, 10, 100};
  cin >> N >> M;
  vector<int> scfinal(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> sbuf >> cbuf;
    sbuf--;
    sc.push_back(pair<int, int>(sbuf, cbuf));
  }
  sort(sc.begin(), sc.end());
  bool exists = true;
  for (int i = 0; i < M; i++) {
    if (scfinal[sc[i].first] == -1) {
      scfinal[sc[i].first] = sc[i].second;
    } else if (scfinal[sc[i].first] != sc[i].second) {
      exists = false;
      break;
    }
  }
  if ((N != 1) && (scfinal[0] == 0)) exists = false;
  int res = -1;
  if (exists) {
    res++;
    for (int i = 0; i < N; i++) {
      res += (scfinal[i] < 0 ? 0 : scfinal[i]) * power10[N - i - 1];
    }
  }
  cout << res << endl;
  return 0;
}
