#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  map<ll, ll> X;
  bool dame = 0;
  for (ll i = 0; i < M; i++) {
    ll s, c;
    cin >> s >> c;
    if (X.count(s) && X[s] != c)
      dame = 1;
    else
      X[s] = c;
  }
  ll ans = 0;
  if (N == 1) {
    for (auto p : X) {
      auto k = p.first;
      auto v = p.second;
      if (k == 1) ans = v;
    }
  } else if (N == 2) {
    for (auto p : X) {
      auto k = p.first;
      auto v = p.second;
      if (k == 2) ans += v;
      if (k == 1 && v == 0)
        dame = 1;
      else if (k == 1)
        ans += v * 10;
    }
  } else if (N == 3) {
    for (auto p : X) {
      auto k = p.first;
      auto v = p.second;
      if (k == 3) ans += v;
      if (k == 2) ans += v * 10;
      if (k == 1 && v == 0)
        dame = 1;
      else if (k == 1)
        ans += v * 100;
    }
  }
  if (dame == 1)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
