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