#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> d(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> d.at(i).at(j);
    }
  }
  vector<int> V(N, -1);
  for (int i = 0; i < M; i++) {
    int s = d.at(i).at(0);
    int c = d.at(i).at(1);
    if (V.at(s - 1) != -1 && V.at(s - 1) != c) {
      V.at(0) = -2;
      break;
    } else
      V.at(s - 1) = c;
  }
  for (int i = 1; i < N; i++) {
    if (V.at(i) == -1) V.at(i) = 0;
  }
  if (V.at(0) = -1) V.at(0) = 1;
  if (V.at(0) == -2) {
    cout << -1;
  } else if (V.at(0) == 0 && N == 1) {
    cout << 0;
  } else if (V.at(0) == 0 && N > 1) {
    cout << -1;
  } else {
    for (int i = 0; i < N; i++) {
      cout << V.at(i);
    }
  }
  cout << endl;
}
