#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[5] = {0};
  bool save[5] = {false};
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int index, digit;
    cin >> index >> digit;
    if (arr[index] >= digit and save[index] == true) {
      arr[index] = digit;
    } else {
      arr[index] = digit;
    }
  }
  if (arr[1] == 0 and n >= 2)
    cout << -1 << endl;
  else {
    for (int i = 1; i <= n; i++) cout << arr[i];
  }
  cout << endl;
}
