#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int>> p;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    p.push_back(tie(s, c));
  }
  int ans = 0;
  if (N >= 2) {
    if (M != 0) {
      bool ok = false;
      for (int i = 0; i < M; i++) {
        if (get<0>(p.at(i)) == 1 && get<1>(p.at(i)) == 0) {
          ok = true;
        }
      }
      sort(p.begin(), p.end());
      for (int i = 0; i < M - 1; i++) {
        if (get<0>(p.at(i)) == get<0>(p.at(i + 1))) {
          if (get<1>(p.at(i)) != get<1>(p.at(i + 1))) {
            ok = true;
          }
        }
      }
      if (ok) {
        cout << -1 << endl;
      } else {
        for (int i = 0; i < M - 1; i++) {
          if (p.at(i) == p.at(i + 1)) {
            continue;
          }
          if (get<0>(p.at(i)) == 1) {
            ans += 100 * get<1>(p.at(i));
          } else if (get<0>(p.at(i)) == 2) {
            ans += 10 * get<1>(p.at(i));
          } else if (get<0>(p.at(i)) == 3) {
            ans += get<1>(p.at(i));
          }
        }
        if (get<0>(p.at(M - 1)) == 1) {
          ans += 100 * get<1>(p.at(M - 1));
        } else if (get<0>(p.at(M - 1)) == 2) {
          ans += 10 * get<1>(p.at(M - 1));
        } else if (get<0>(p.at(M - 1)) == 3) {
          ans += get<1>(p.at(M - 1));
        }
        cout << ans << endl;
      }
    } else {
      if (N == 3) {
        cout << 100 << endl;
      } else if (N == 2) {
        cout << 10 << endl;
      } else if (N == 1) {
        cout << 0 << endl;
      }
    }
  } else {
    if (M != 0) {
      bool ok = false;
      sort(p.begin(), p.end());
      for (int i = 0; i < M; i++) {
        if (get<0>(p.at(i)) >= 2) {
          ok = true;
        }
      }
      for (int i = 0; i < M - 1; i++) {
        if (get<0>(p.at(i)) == get<0>(p.at(i + 1))) {
          if (get<1>(p.at(i)) != get<1>(p.at(i + 1))) {
            ok = true;
          }
        }
      }
      if (ok) {
        cout << -1 << endl;
      } else {
        cout << get<1>(p.at(0)) << endl;
      }
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
