#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  vector<pair<int, int>> s;
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    s.push_back(make_pair(a, b));
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < M - 1; i++) {
    if (s[i].first != 1 || s[i].second != 0) {
      break;
    }
    cout << 0;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    if ((s[i].second == 0 && s[i].first == 1) ||
        (i < M - 1 && s[i].first == s[i + 1].first &&
         s[i].second != s[i + 1].second)) {
      cout << -1;
      return 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (s[i].first == 1) {
      ans += 100 * s[i].second;
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    if (s[i].first == 2) {
      ans += 10 * s[i].second;
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    if (s[i].first == 3) {
      ans += s[i].second;
      break;
    }
  }
  if (ans < 100) {
    ans += 100;
  }
  cout << ans;
}
