#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, s;
  cin >> n >> m;
  char c;
  set<pair<long long, char>> st;
  for (long long(i) = 0; (i) < (m); ++(i)) {
    cin >> s >> c;
    st.insert(pair<long long, long long>(s, c));
  }
  bool isok = true;
  string str;
  for (long long(i) = 0; (i) < (n); ++(i)) str += '0';
  for (pair<long long, long long> p : st) {
    if (str[p.first - 1] != '0') {
      isok = false;
      break;
    }
    str[p.first - 1] = p.second;
  }
  long long ans = 0;
  if (!isok)
    ans = -1;
  else {
    if (str[0] == '0' && n > 1)
      ans = -1;
    else
      ans = stoll(str);
  }
  cout << (ans) << endl;
  return 0;
}
