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