#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
int main() {
  int i, j, n, m;
  int s[5], c[5];
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  int ans = 0;
  for (int i = 0; i < m; ++i)
    ;
  {
    for (int j = 0; j < m; ++j)
      ;
    {
      if ((s[i] == s[j]) && (c[i] != c[j])) {
        ans = -1;
        goto OUT;
      }
    }
  }
  for (int i = 0; i < m; ++i)
    ;
  {
    if ((s[i] == 1) && (c[i] == 0)) {
      ans = -1;
      cout << ans << endl;
      goto OUT;
    } else {
      ans += 10 * (s[i] - 1) * c[i];
    }
  }
OUT:
  cout << ans << endl;
}
