#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string num = "";
  for (int i = 0; i < n; i++) num += '0';
  bool isPossible = true;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    char y;
    cin >> y;
    if (num[x - 1] != '0')
      if (num[x - 1] != y) isPossible = false;
    if (x > n || (x == 1 && y == '0')) isPossible = false;
    num[x - 1] = y;
  }
  if (num[0] == '0') num[0] = 1;
  if (isPossible == true)
    cout << num << endl;
  else
    cout << -1 << endl;
  return 0;
}
