#include <bits/stdc++.h>
using namespace std;
signed main() {
  int i = 0, j = 0, k = 0, ans = 0;
  int n, m, s[5] = {0}, cnt = 0;
  char c[5] = {0};
  cin >> n >> m;
  for (i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (i = 0; i < m; i++) {
    if ((s[i] == 1) && (c[i] == '0') && (n > 1)) {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] == n) cnt++;
  }
  string answer = "aaa";
  for (i = 0; i < m; i++) {
    if ((answer[s[i] - 1] != 'a') && (answer[s[i] - 1] != c[i])) {
      cout << -1 << endl;
      return 0;
    } else {
      answer[s[i] - 1] = c[i];
      k++;
    }
  }
  if (cnt == 0) answer[0] = '1';
  for (j = 0; j < n; j++) {
    if (answer[j] == 'a') answer[j] = '0';
  }
  for (i = 0; i < n; i++) {
    cout << answer[i];
  }
  cout << endl;
  return 0;
}
