#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m, ans = 0;
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  for (long long i = (0); i < (m); i++) cin >> s[i] >> c[i];
  for (long long i = (0); i < (m); i++) {
    bool flag = true;
    if (s[i] == 1 and n != 1 and c[i] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    for (long long j = (0); j < (m); j++) {
      if (s[i] == s[j] and i < j) {
        if (c[i] != c[j]) {
          cout << -1 << "\n";
          return 0;
        } else
          flag = false;
      }
    }
    if (flag) ans += (c[i] * pow(10, n - s[i]));
  }
  cout << ans << "\n";
}
