#include <bits/stdc++.h>
using namespace std;
bool comp(const int& a, const int& b) { return a > b; }
int main() {
  int N, M, ANS = 0;
  cin >> N >> M;
  vector<pair<int, int>> vec;
  if (M == 0) {
    if (N == 1) cout << 0 << endl;
    if (N == 2) cout << 10 << endl;
    if (N == 3) cout << 100 << endl;
  } else {
    for (long long i = (0); i < (M); i++) {
      int t1, t2;
      cin >> t1 >> t2;
      vec.push_back(make_pair(t1, t2));
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    for (long long i = (0); i < (vec.size() - 1); i++)
      if (vec[i].first == vec[i + 1].first &&
          vec[i].second != vec[i + 1].second)
        ANS = -1;
    if (ANS == -1) {
      cout << "-1" << endl;
    } else if (vec[0].second == 0 && vec[0].first == N) {
      cout << "-1" << endl;
    } else {
      for (long long i = (0); i < (vec.size()); i++) {
        if (vec[i].first == 1 && N == 1) ANS = ANS + vec[i].second;
        if (vec[i].first == 1 && N == 2) ANS = ANS + vec[i].second * 10;
        if (vec[i].first == 2 && N == 2) ANS = ANS + vec[i].second;
        if (vec[i].first == 1 && N == 3) ANS = ANS + vec[i].second * 100;
        if (vec[i].first == 2 && N == 3) ANS = ANS + vec[i].second * 10;
        if (vec[i].first == 3 && N == 3) ANS = ANS + vec[i].second;
      }
      if (ANS == 0) {
        cout << "-1" << endl;
      } else {
        cout << ANS << endl;
      }
    }
  }
}
