#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;
int main(int argc, char *argv[]) {
  ll n, m;
  cin >> n >> m;
  if (m == 0) {
    n == 1 ? cout << 0 << endl : cout << -1 << endl;
  }
  char ans[n];
  for (ll i = 0; i < n; i++) {
    ans[i] = 'X';
  }
  for (ll i = 0; i < m; i++) {
    ll s;
    char c;
    cin >> s >> c;
    if (ans[n - s] != 'X' && ans[n - s] != c) {
      cout << -1 << endl;
      exit(0);
    }
    ans[n - s] = c;
  }
  if (ans[n - 1] == '0') {
    cout << -1 << endl;
    exit(0);
  }
  for (ll i = 0; i < n; i++) {
    if (ans[n - i] == 'X') ans[n - i] = '0';
  }
  ll ret = 0;
  for (ll i = 0; i < n; i++) {
    ll pwd = pow(10, n - i - 1);
    ll dig = ans[n - i - 1] - '0';
    ret += pwd * dig;
  }
  cout << ret << endl;
}
