#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFS = 1e18;
const int MOD = INF + 7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  map<int, int> mp;
  bool ja = true;
  for (int i = 0; i < (n); i++) {
    mp[i + 1] = -1;
  }
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) ja = false;
    if (mp[s] == -1) {
      mp[s] = c;
      if (s == 1) {
        ans += c * 100;
      }
      if (s == 2) {
        ans += c * 10;
      }
      if (s == 3) {
        ans += c;
      }
    } else {
      if (mp[s] != c) {
        ja = false;
      }
    }
  }
  if (ja) {
    cout << ans << endl;
    return 0;
  }
  cout << -1 << endl;
}
