#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll N, M;
  cin >> N >> M;
  vll check(10, -1);
  bool ok = true;
  ll ans = 0;
  for (ll i = 0; i < (M); i++) {
    ll s, c;
    cin >> s >> c;
    if (N < s)
      ok = false;
    else if (check[s] == -1) {
      check[s] = c;
      ans += pow(10, N - s) * c;
    } else if (check[s] != c)
      ok = false;
  }
  ll tmp = ans, dig = 0;
  while (tmp) {
    tmp /= 10;
    dig++;
  }
  if (dig != N) ok = false;
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
