#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  string ans = "";
  for (int i = 0; i < n; ++i) {
    ans += 'd';
  }
  for (int i = 0; i < m; ++i) {
    if (ans[s[i] - 1] == 'd') {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] == c[i]) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == 'd') {
    ans[0] = '1';
  }
  for (int i = 1; i < n; ++i) {
    if (ans[i] == 'd') {
      ans[i] = '0';
    }
  }
  bool flg = false;
  for (int i = 0; i < n; ++i) {
    if (ans[i] != '0') {
      flg = true;
    }
  }
  cout << (flg ? ans : "-1") << endl;
}
