#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
long long inputValue() {
  long long a;
  cin >> a;
  return a;
};
void inputArray(int* p, long long a) {
  for (long long i = (0); i < (a); i++) {
    cin >> p[i];
  }
};
template <typename T>
void inputVector(vector<T>& p, long long a) {
  for (long long i = (0); i < (a); i++) {
    T input;
    cin >> input;
    p.emplace_back(input);
  }
}
template <typename T>
void output(T a) {
  cout << a << "\n";
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> sc(m);
  for (long long i = 0; i < m; ++i) {
    long long a, b;
    cin >> a >> b;
    sc[i] = make_pair(a, b);
    if (a == 1 && b == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  sort(sc.begin(), sc.end(), greater<pair<long long, long long>>());
  sc.erase(unique(sc.begin(), sc.end()), sc.end());
  long long out = 0;
  for (auto p : sc) {
    switch (p.first) {
      case 3:
        if (out > 0) {
          cout << -1 << endl;
          return 0;
        }
        out += p.second * 1;
        break;
      case 2:
        if (out > 10) {
          cout << -1 << endl;
          return 0;
        }
        out += p.second * 10;
        break;
      case 1:
        if (out > 100) {
          cout << -1 << endl;
          return 0;
        }
        out += p.second * 100;
        break;
    }
  }
  cout << out << endl;
  return 0;
}
