#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans = 0, kake = 100;
  bool flag = true;
  set<int> sdic;
  set<int> cdic;
  cin >> N >> M;
  if (N == 2) kake = 10;
  if (N == 1) kake = 1;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (sdic.count(s) && cdic.count(c))
      continue;
    else if (sdic.count(s) && !cdic.count(c)) {
      flag = false;
      break;
    }
    if (s == 1) ans += kake * c;
    if (s == 2)
      ans += kake / 10 * c;
    else if (s == 3)
      ans += kake / 100 * c;
    sdic.insert(s);
    cdic.insert(c);
  }
  if (flag && ans != 0)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
