#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, n, m, temp1 = 0, temp2 = 0;
  cin >> N >> M;
  vector<int> vec(N);
  vector<int> zero(N);
  for (int i = 0; i < M; i++) {
    cin >> n >> m;
    if (N != 1) {
      if (n == 1) {
        if (m == 0) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (temp1 == n) {
      if (temp2 != m) {
        cout << -1 << endl;
        return 0;
      }
    }
    temp1 = n;
    temp2 = m;
    vec.at(n - 1) = m;
  }
  if (vec == zero) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (i = 0) {
      if (vec.at(i) == 0) continue;
    }
    cout << vec.at(i);
  }
  cout << endl;
  return 0;
}
