#include <bits/stdc++.h>
using namespace std;
struct p {
  int s, c;
} a[10];
bool comparison(p a, p b) { return a.s > b.s; }
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0 && n > 1) {
    cout << pow(10, n - 1) << endl;
    return 0;
  }
  if (n == 1 && m == 0) {
    cout << 0 << endl;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i].s >> a[i].c;
  }
  sort(a + 1, a + m + 1, comparison);
  if (a[1].s < n) {
    cout << -1 << endl;
  } else {
    int sum[10] = {0};
    for (int i = m; i >= 1; i--) {
      sum[i] = a[i].c * pow(10, n - a[i].s);
    }
    sort(sum + 1, sum + m);
    int ans = 0;
    for (int i = 1; i <= m; i++) {
      if (sum[i] == sum[i + 1]) {
        continue;
      }
      ans += sum[i];
    }
    cout << ans << endl;
  }
  return 0;
}
