#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, x[10], y[10], j, s = 0, k = 1, z[10], w[10], h = 0, t,
                                      u = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= m; j++) {
      if (x[j] > x[i]) {
        long long tmp = x[i];
        x[i] = x[j];
        x[j] = tmp;
        long long tmp2 = y[i];
        y[i] = y[j];
        y[j] = tmp2;
      }
    }
  }
  x[0] = 0;
  for (i = 1; i <= m; i++) {
    if (x[i] != x[i - 1]) {
      z[k] = x[i];
      w[k] = y[i];
      k++;
    } else if (x[i] == x[i - 1]) {
      if (y[i] != y[i - 1]) {
        h++;
      }
    }
  }
  for (i = 1; i < k; i++) {
    if (z[i] == 1) {
      s = s + (w[i] * 100);
    } else if (z[j] == 2) {
      s = s + (w[i] * 10);
    } else {
      s = s + w[i];
    }
  }
  if (h == 0) {
    t = s;
    while (t != 0) {
      t /= 10;
      u++;
    }
    if (u == n) {
      cout << s << endl;
    } else {
      cout << "-1" << endl;
    }
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
