#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  bool ju = true;
  vector<int> num(N, 0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num.at(s) == 0) {
      num.at(s) = c;
    } else if (num.at(s) != c) {
      ju = false;
      break;
    } else
      ;
  }
  if (num.at(0) == 0) {
    ju = false;
  }
  if (!ju) {
    cout << -1;
  } else {
    for (int i = 0; i < N; i++) {
      cout << num.at(i);
    }
  }
  cout << endl;
}
