#include <bits/stdc++.h>
using namespace std;
char a[8];
int main() {
  for (int i = 0; i < 8; i++) a[i] = '0';
  int n, m;
  cin >> n >> m;
  char a1, b;
  int manx = 0, minx = 999;
  for (int i = 0; i < m; i++) {
    cin >> a1 >> b;
    a[a1 - '0'] = b;
    if (a1 - '0' > manx) manx = a1 - '0';
    if (a1 - '0' < minx) minx = a1 - '0';
  }
  if (manx - minx < n) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) cout << a[i];
}
