#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  map<int, int> info;
  int ans_min;
  switch (N) {
    case 1:
      ans_min = 0;
      break;
    case 2:
      ans_min = 10;
      break;
    case 3:
      ans_min = 100;
      break;
  }
  vector<int> s_prev(M);
  vector<int> c_prev(M);
  bool end_flag = false;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (i != 0) {
      for (int j = 0; j < i; j++) {
        if (s.at(i) == s_prev.at(j) && c.at(i) != c_prev.at(j) ||
            s.at(i) == 1 && c.at(i) == 0) {
          end_flag = true;
        }
      }
    }
    s_prev.at(i) = s.at(i);
    c_prev.at(i) = c.at(i);
  }
  if (end_flag) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    info[s.at(i)] = c.at(i);
  }
  int est = 0;
  for (auto p : info) {
    auto s = p.first;
    auto c = p.second;
    est += c * pow(10, N - s);
  }
  if (N >= 2) {
    if (est < pow(10, N - 1)) {
      est += 1 * pow(10, N - 1);
      cout << est << endl;
      return 0;
    }
  }
  cout << est << endl;
}
