#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool C = 1;
  vector<int> V(N);
  (i, N) for (int i = 0; i < N; i++)(i, M) {
    int a, b;
    cin >> a >> b;
    if (b != 0) C = 0;
    if (V[a - 1] != 0 && V[a - 1] != b) {
      C = 1;
      break;
    } else
      V[a - 1] = b;
  }
  if (C)
    cout << "-1";
  else
    (i, N) for (int i = 0; i < N; i++)(i, N) cout << V[i];
}
