#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  for (ll i = 0; i < m; i++) {
    ll s, c;
    cin >> s >> c;
    if (mp.count(s)) {
      mp[s] = min(mp[s], c);
    } else {
      mp[s] = c;
    }
  }
  ll ans = 0;
  for (auto p : mp) {
    ll tmp = p.second;
    for (ll i = 0; i < n - p.first; i++) {
      tmp *= 10;
    }
    ans += tmp;
  }
  if (n == 1 && ans == 0) {
    cout << ans << endl;
    return 0;
  }
  ll tmp = ans;
  ll dig = 0;
  while (tmp > 0) {
    tmp /= 10;
    dig++;
  }
  if (dig == n) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
