#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  const int INF = 9999;
  int N, M;
  cin >> N >> M;
  vector<int> value(3, INF);
  for (int i = 0; i < (M); ++i) {
    int s;
    int c;
    cin >> s >> c;
    if (value.at(3 - s) == INF || value.at(3 - s) == c) {
      value.at(3 - s) = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = N; i < 3; ++i) {
    if (value.at(i) != INF) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (value.at(N - 1) == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (value.at(N - 1) == INF) {
    value.at(N - 1) = 1;
  }
  for (int i = 0; i < (N - 1); ++i) {
    if (value.at(i) == INF) {
      value.at(i) = 0;
    }
  }
  cout << value.at(0) + value.at(1) * 10 + value.at(2) * 100 << endl;
  return 0;
}
