#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1e9 + 7;
signed main() {
  long long n, m, arr[3] = {}, s, c;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) arr[i] = -1;
  bool ok = 1;
  while (cin >> s >> c) {
    if (n != 1 && s == 1 && c == 0) ok = 0;
    if (arr[s - 1] != -1 && arr[s - 1] != c) ok = 0;
    arr[s - 1] = c;
  }
  if (!ok) cout << -1 << endl, exit(0);
  long long ans = 0;
  long long a[] = {1, 10, 100};
  for (long long i = 0; i < n; i++)
    if (arr[i] != -1) ans += arr[i] * a[n - 1 - i];
  cout << ans << endl;
}
