#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
int main(int argc, char const* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  string ans(N, '0');
  vector<bool> editflg(N, false);
  int digit;
  char tmp;
  for (int i = (0); i < (M); i++) {
    cin >> digit;
    cin >> tmp;
    if (!editflg[digit - 1] || ans[digit - 1] == tmp) {
      ans[digit - 1] = tmp;
      editflg[digit - 1] = true;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (ans[0] == '0' && ans.size() > 1) {
    ans[0] = '1';
    cout << ans << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
