#include <bits/stdc++.h>
using namespace std;
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
  return os << "( " << p.first << ", " << p.second << " )";
}
template <class t>
ostream &operator<<(ostream &os, const vc<t> &second) {
  os << "[ ";
  for (int i = 0; i < second.size(); i++) {
    os << second[i];
    if (i != second.size() - 1) {
      os << ", ";
    }
  }
  return os << " ]";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> dict;
  vc<int> second(n + 1, 0);
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (second[s] != 0 && second[s] != c) {
      cout << -1 << "\n";
      return 0;
    }
    second[s] = c;
  }
  int count = 0;
  for (int i = 0; i <= m; i++) {
    if (second[i] == 0) {
      count++;
    } else {
      break;
    }
  }
  if (second.size() - count >= n) {
    string s;
    for (auto &i : second) {
      s += to_string(i);
    }
    int r = stoi(s);
    cout << r << "\n";
  } else {
    cout << -1 << "\n";
  }
}
