#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> a(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> a.at(i).at(0) >> a.at(i).at(1);
  }
  vector<int> b(N, 0);
  int record = 0;
  for (int i = 0; i < M; i++) {
    if (b.at(a.at(i).at(0) - 1) == 0 ||
        b.at(a.at(i).at(0) - 1) == a.at(i).at(1)) {
      b.at(a.at(i).at(0) - 1) = a.at(i).at(1);
    } else {
      record++;
    }
  }
  if (b.at(0) != 0) {
    for (int i = 0; i < N; i++) {
      cout << b.at(i);
    }
    cout << endl;
  } else if (record = !0) {
    cout << -1 << endl;
  } else {
    cout << -1 << endl;
  }
}
