#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<char> res(n, 0);
  for (long long i = 1; i <= m; i++) {
    long long s;
    char c;
    cin >> s >> c;
    s--;
    if (res[s] == 0)
      res[s] = c;
    else if (res[s] != c) {
      cout << -1 << '\n';
      return;
    }
  }
  if (res[0] == '0') {
    cout << -1 << '\n';
    return;
  }
  if (res[0] == 0 && n > 1) {
    res[0] = '1';
  }
  for (auto &i : res) {
    if (i == 0)
      cout << '0';
    else
      cout << i;
  }
  cout << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long T = 1;
  while (T--) solve();
}
