#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int dig(int a, int n) {
  if (a == 1 && n == 3) {
    return 100;
  } else if (n == 2 && a == 1 || n == 3 && a == 2) {
    return 10;
  } else if (a == 0) {
    return 0;
  } else if (a == n) {
    return 1;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m - 1; ++i) {
    for (int j = i + 1; j < m; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      } else if (s[i] == s[j] && c[i] == c[j]) {
        s[j] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += c[i] * dig(s[i], n);
  }
  cout << ans << endl;
  return 0;
}
