#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  bool b[4] = {};
  cin >> N >> M;
  map<int, int> m;
  for (int i = 1; i <= 3; i++) {
    m[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (!b[s]) {
      b[s] = true;
      m[s] = c;
    } else {
      if (c == m[s]) continue;
      cout << -1 << endl;
      return 0;
    }
  }
  if (m[N] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (auto A : m) {
    auto value = A.second;
    cout << value;
  }
  cout << endl;
}
