#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, NUM, ERROR;
  cin >> N >> M;
  vector<int> NUMwork(N);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (NUMwork.at(s - 1) != 0 || NUMwork.at(s - 1) != c) {
      ERROR = 1;
      break;
    } else {
      NUMwork.at(s - 1) = c;
    }
  }
  for (int i = 0; i < M; i++) {
    NUM = NUM + NUMwork.at(i) * std::pow(10, N - i - 1);
  }
  if (ERROR == 1) {
    cout << -1 << endl;
  } else {
    if (NUM >= std::pow(10, N - 1) || NUM < std::pow(10, N)) {
      cout << NUM << endl;
    } else {
      cout << -1 << endl;
    }
  }
}
