#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int sc[m];
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1) {
      sc[i] = 100 * c;
    } else if (s == 2) {
      sc[i] = 10 * c;
    } else {
      sc[i] = 1 * c;
    }
  }
  int ans = 1000;
  for (int i = 0; i < m; i++) {
    int sum = sc[i];
    for (int j = i + 1; j < m; j++) {
      sum += sc[j];
      if (to_string(sum).length() == n) {
        ans = min(ans, sum);
      }
    }
  }
  if (ans == 1000) ans = -1;
  cout << ans << endl;
  ;
}
