#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s1;
  char c1;
  cin >> N >> M;
  char* str = new char[N];
  for (int i = 0; i < N; i++) {
    str[i] = '0';
  }
  for (int i = 0; i < M; i++) {
    cin >> s1 >> c1;
    if (s1 == 1 and c1 == '0') {
      cout << -1;
      return 0;
    }
    if (i >= 1 and str[s1 - 1] != c1 and c1 != '0') {
      cout << -1;
      return 0;
    }
    str[s1 - 1] = c1;
  }
  for (int i = 0; i < N; i++) {
    cout << str[i];
  }
  return 0;
}
