#include <bits/stdc++.h>
using namespace std;
long long int vis[200010];
int main() {
  long long int n, m, i, j, k, p = 0, a, b;
  string s = "";
  char ch;
  cin >> n >> m;
  for (i = 1; i <= n; i++) s += '1';
  while (m--) {
    cin >> a >> ch;
    if (vis[a] == 0) {
      s[a - 1] = ch;
      vis[a] = 1;
    } else {
      if (ch != s[a - 1]) {
        p = 1;
      }
    }
  }
  if (p == 0 && s[0] != '0')
    cout << s << endl;
  else
    cout << -1 << endl;
  return 0;
}
