#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  map<long, int> a;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a.find(x) != a.end()) {
      a[x] = min(a[x], y);
    } else {
      a[x] = y;
    }
  }
  int ans = 0;
  for (auto itr = a.begin(); itr != a.end(); itr = next(itr, 1)) {
    ans += itr->second * pow(10, 3 - itr->first);
  }
  if (to_string(ans).size() < n)
    cout << -1;
  else
    cout << ans;
  return 0;
}
