#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[3] = {0};
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    a[s - 1] = c;
  }
  if (n == 3 && a[0] == 0)
    cout << -1;
  else if (n == 2 && (a[1] == 0 || a[0] > 0))
    cout << -1;
  else if (n == 1)
    cout << a[2];
  else if (n == 2)
    cout << a[1] << a[2];
  else
    cout << a[0] << a[1] << a[2];
  return 0;
}
