#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p) {
  os << "(" << p.first << ": " << p.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << "(";
  for (auto& i : v) os << i << ", ";
  os << ")";
  return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, map<K, V> m) {
  os << "{";
  for (auto& i : m) os << i << ", ";
  os << "}";
  return os;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> sc(m);
  for (long long i = 0; i < m; ++i) {
    long long s, c;
    cin >> s >> c;
    s--;
    sc[i] = make_pair(s, c);
  }
  vector<set<long long>> nn(n);
  for (auto& i : sc) {
    long long s = i.first;
    long long c = i.second;
    if (s == 0 && c == 0) continue;
    nn[s].insert(c);
  }
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    if (nn[i].empty()) continue;
    if (nn[i].size() > 1) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = nn[i].begin();
    ans += *itr * long long(pow(10, n - i - 1));
  }
  if (ans < long long(pow(10, n - 1)) && n > 1) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
