#include <bits/stdc++.h>
int main(void) {
  int n, m, checker = 0, counter = 1, ans = 0;
  scanf("%d%d", &n, &m);
  int s[m + 1], c[m + 1];
  while (checker < m) {
    scanf("%d%d", &s[checker], &c[checker]);
    checker++;
  }
  checker = 0;
  while (checker < m) {
    counter = 1;
    while (checker + counter < m) {
      if (s[checker] == s[checker + counter]) {
        if (c[checker] != c[checker + counter]) {
          ans = -1;
        }
      }
      counter++;
    }
    checker++;
  }
  checker = 0;
  while (checker < m) {
    if (n == s[checker]) {
      if (c[checker] == 0) {
        if (n != 1) {
          ans = -1;
        }
      }
    }
    checker++;
  }
  checker = 0;
  if (ans != -1) {
    while (checker < m) {
      if ((n - s[checker]) == 0) {
        ans += c[checker];
        break;
      }
      checker++;
    }
    checker = 0;
    while (checker < m) {
      if ((n - s[checker]) == 1) {
        ans += (10 * c[checker]);
        break;
      }
      checker++;
    }
    checker = 0;
    while (checker < m) {
      if ((n - s[checker]) == 2) {
        ans += (100 * c[checker]);
        break;
      }
      checker++;
    }
  }
  printf("%d", ans);
  return 0;
}
