#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<pair<int, int>> s(m);
  for (int i = 0; i < m; i++) cin >> s[i].first >> s[i].second;
  sort(s.begin(), s.end());
  for (int i = 0; i < m; i++) {
    if (i >= 1) {
      if (s[i - 1].first == s[i].first) {
        if (s[i - 1].second != s[i].second) {
          ans = -1;
          break;
        }
      } else {
        int num = n - s[i].first;
        if (num == 2) num = 100;
        if (num == 1) num = 10;
        if (num == 0) num = 1;
        ans += s[i].second * num;
      }
    }
    if (s[i].first == 1 && n > 1) {
      if (s[i].second == 0) {
        ans = -1;
        break;
      }
    }
    if (i == 0) {
      int num = n - s[i].first;
      if (num == 2) num = 100;
      if (num == 1) num = 10;
      if (num == 0) num = 1;
      ans += s[i].second * num;
    }
  }
  if (n == 2 && ans < 10) ans += 10;
  if (n == 3 && ans < 100) ans += 100;
  cout << ans << endl;
  return 0;
}
