#include <bits/stdc++.h>
int main() {
  int N, M;
  int i;
  i = 0;
  if (scanf("%d %d", &N, &M))
    ;
  int s[M], c[M], sum[M], digit, j, ans;
  while (i++ < M) {
    if (scanf("%d %d", &s[i], &c[i]))
      ;
    j = 0;
    digit = 1;
    while (j++ < s[i] - 1) digit *= 10;
    sum[i] = c[i] * digit;
  }
  int check_i = 0;
  int check_j;
  while (check_i++ < M) {
    check_j = check_i;
    while (check_j++ < M) {
      if (sum[check_i] == sum[check_j]) {
        if (c[check_i] != c[check_j]) {
          printf("-1");
          break;
        }
      } else if (check_i == M - 1 && check_j == M) {
        int i = 0;
        while (i++ < M) ans += sum[check_j];
        printf("%d", ans);
      }
    }
  }
  return (0);
}
