#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a, b, c, n, maxi = 0, f = 0, mini = 1001001001;
  long long sum = 0;
  string str, sub;
  long long h, w;
  long long m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else if (n == 2) {
      cout << 10 << endl;
    } else {
      cout << 100 << endl;
    }
    return 0;
  }
  vector<pair<long long, long long>> s(m);
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    cin >> a >> b;
    s[i] = make_pair(a, b);
    if (b != 0 && a == n) f = 1;
  }
  if (f == 0) {
    cout << -1 << endl;
  }
  f = 0;
  sort(s.begin(), s.end());
  sum = 0;
  if (s[0].first == 1) {
    if (s[0].second == 0 && n != 1) f = 1;
    sum += 100 * s[0].second;
  }
  if (s[0].first == 2) {
    sum += 10 * s[0].second;
  }
  if (s[0].first == 3) {
    sum += 1 * s[0].second;
  }
  for (long long i = 1; i < m; i++) {
    if (s[i - 1].first == s[i].first && s[i - 1].second != s[i].second)
      f = 1;
    else if (s[i - 1].first == s[i].first && s[i - 1].second == s[i].second)
      continue;
    else {
      if (s[i].first == 1) {
        if (s[i].second == 0 && n != 1) f = 1;
        sum += 100 * s[i].second;
      }
      if (s[i].first == 2) {
        sum += 10 * s[i].second;
      }
      if (s[i].first == 3) {
        sum += 1 * s[i].second;
      }
    }
  }
  if (n == 1 && sum != 0) sum /= 100;
  if (n == 2 && sum != 0) sum /= 10;
  if (n == 3 && sum != 0 && sum < 100) sum += 100;
  if (n == 2 && sum != 0 && sum < 10) sum += 10;
  if (f != 1 && sum == 0 && n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (f == 1) {
    cout << "-1" << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}
