#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
using ll = long long;
using P = pair<long long, long long>;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> res(n, -1);
  for (long long i = 0; i < (m); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (res[a] != -1 && res[a] != b) {
      cout << -1 << endl;
      return 0;
    }
    res[a] = b;
  }
  if (res[0] == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    cout << -1 << endl;
    return 0;
  }
  if (res[0] == -1) res[0] = 1;
  for (long long i = 0; i < (n); i++) {
    if (res[i] == -1) res[i] = 0;
  }
  long long ret = 0;
  for (long long i = 0; i < (res.size()); i++) {
    ret *= 10;
    ret += res[i];
  }
  cout << ret << endl;
  return 0;
}
