#include <bits/stdc++.h>
using namespace std;
int a[4], n, m;
bool f[4];
int main() {
  cin >> n >> m;
  int i, j;
  while (m--) {
    cin >> i >> j;
    if (a[i] > j || !f[i]) {
      a[i] = j;
      f[i] = 1;
    }
  }
  if (a[1] == 0)
    cout << -1;
  else
    for (int k = 1; k <= n; k++) cout << a[k];
}
