#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long mod2 = 998244353;
const int INF = 1e9;
signed main() {
  long long n, m;
  cin >> n >> m;
  string s = "";
  for (int i = 0; i < (int)(n); i++) s += "0";
  bool unko = true;
  for (int i = 0; i < (int)(m); i++) {
    long long a;
    char b;
    cin >> a >> b;
    a--;
    if (s[a] != '0' && s[a] != b) unko = false;
    s[a] = b;
  }
  if (s[0] == '0') s[0] = 1;
  if (unko)
    cout << s << '\n';
  else
    cout << -1 << '\n';
}
