#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<char> res(n, '.');
  bool f = true;
  for (int i = 0; i < m; ++i) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (res[s] != '.' && res[s] != c) {
      f = false;
    }
    res[s] = c;
  }
  for (int i = 0; i < n; ++i) {
    if (res[i] == '.') res[i] = '0';
  }
  if (f == false || (res[0] == '0' && n != 1)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cout << res[i];
  }
  cout << endl;
  return 0;
}
