#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e9;
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  vector<pair<long long int, long long int> > b(m);
  for (long long int i = 0; i < m; i++) {
    long long int s, c;
    cin >> s >> c;
    b[i] = pair<long long int, long long int>(s, c);
  }
  sort(b.begin(), b.end());
  auto it = unique(b.begin(), b.end());
  m = it - b.begin();
  for (long long int i = 0; i < m - 1; i++) {
    if (b[i].first == b[i + 1].first) {
      cout << -1 << endl;
      return 0;
    }
  }
  long long int sum = 0;
  for (long long int i = 0; i < m; i++) {
    sum += pow(10, 3 - b[i].first) * b[i].second + 0.5;
  }
  long long int keta = pow(10, n - 1) + 0.5;
  if (sum / keta == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << sum << endl;
  return 0;
}
