#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int answer = 0;
  int flag[N];
  for (int i = 0; i < N; i++) flag[i] = -1;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s <= N && flag[s - 1] == -1) {
      flag[s - 1] = c;
      if (N == 3 && s == 1)
        answer += c * 100;
      else if ((N == 2 && s == 1) || (N == 3 && s == 2))
        answer += c * 10;
      else if ((N == 1 && s == 1) || (N == 2 && s == 2) || (N == 3 && s == 3))
        answer += c;
    } else {
      if (flag[s - 1] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (N == 1 && answer >= 0)
    cout << answer << endl;
  else if (N == 2 && answer - 10 >= 0)
    cout << answer << endl;
  else if (N == 3 && answer - 100 >= 0)
    cout << answer << endl;
  else
    cout << -1 << endl;
  return 0;
}
