#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
template <typename T>
ll gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
ll lcm(T a, T b) {
  return a * b / gcd(a, b);
};
template <typename T>
inline void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <typename T>
inline void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  vector<pair<int, int>> vec(m);
  for (int i = 0; i < m; ++i) {
    cin >> vec[i].first >> vec[i].second;
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < m; ++i) {
    if (vec[i].first == vec[i - 1].first && i > 0) {
      if (vec[i].second != vec[i - 1].second) {
        cout << -1 << '\n';
        ;
        return 0;
      }
    }
    if (vec[i].first == 1 && vec[i].second == 0 && n != 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  sort(vec.begin(), vec.end());
  if (vec[0].first != 1) {
    ans += pow(10, n - 1);
  }
  for (int cnt = 1; cnt <= 3;) {
    for (int i = 1; i < m; ++i) {
      if (vec[i].first == cnt) {
        ans += vec[i].second * pow(10, n - cnt);
        cnt++;
        break;
      }
    }
    cnt++;
  }
  cout << ans << '\n';
  return 0;
}
