#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> memo = {};
  long long s, c;
  for (auto i = 0; i < m; i++) {
    cin >> s >> c;
    if (memo.count(s)) {
      if (memo[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    } else {
      memo[s] = c;
    }
  }
  long long ans = 0;
  long long saijoui = -1;
  if (memo.count(1)) {
    ans += 100 * memo[1];
    saijoui = memo[1];
  }
  if (memo.count(2)) {
    ans += 10 * memo[2];
    if (saijoui == -1) {
      saijoui = memo[2];
    }
  }
  if (memo.count(3)) {
    ans += memo[3];
    if (saijoui == -1) {
      saijoui = memo[3];
    }
  }
  if (saijoui == -1 || saijoui == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
