#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
int main() {
  int n, m;
  cin >> n >> m;
  string s(n, '-');
  bool f = true;
  for (int i = 0; (i) < (int)(m); i++) {
    int a;
    char c;
    cin >> a >> c;
    a--;
    if (s[a] == '-')
      s[a] = c;
    else if (s[a] != c)
      f = false;
  }
  for (int i = 0; (i) < (int)(n); i++) {
    if (s[i] == '-') s[i] = '0';
  }
  if (s[0] == '0') f = false;
  string mi = "-1";
  cout << (f ? s : mi);
}
