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