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