#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;
  map<ll, ll> mp;
  if (m == 0) {
    cout << pow(10, n - 1) << '\n';
  } else {
    for (ll i = 0; i < m; ++i) {
      ll a, b;
      cin >> a >> b;
      if (a == 1 && b == 0 && n != 1) {
        cout << -1 << '\n';
        return 0;
      } else if (mp.count(a)) {
        if (mp[a] != b) {
          cout << -1 << '\n';
          return 0;
        }
      } else {
        mp[a] = b;
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (mp.count(i)) {
        ans += mp[i] * pow(10, n - i);
      } else if (i == 1) {
        ans += pow(10, n - i);
      }
    }
    cout << ans << '\n';
  }
}
