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