#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  bool check = true;
  int a = 0;
  for (int j = 0; j < m; j++) {
    for (int k = 0; k < m; k++) {
      if (j == k) continue;
      if (s[j] == s[k] && c[j] != c[k]) check = false;
    }
  }
  if (!check)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (i + 1 == s[j]) {
          if (i + 1 == 1)
            a += c[j] * 100;
          else if (i + 1 == 2)
            a += c[j] * 10;
          else if (i + 1 == 3)
            a += c[j];
          break;
        }
      }
    }
    if (a == 0)
      cout << -1 << endl;
    else
      cout << a << endl;
  }
}
