#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  a = 0;
  b = 0;
  c = 0;
  int n, m, x, y;
  cin >> n >> m;
  if (m == 0) a = 1;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (x == 1) a = y;
    if (x == 2) b = y;
    if (x == 3) c = y;
  }
  int ans = a;
  if (n == 2) ans = (a * 10) + b;
  if (n == 3) ans = (((a * 10) + b) * 10) + c;
  int tmp = ans;
  int cnt = 0;
  while (tmp > 0) {
    tmp /= 10;
    cnt++;
  }
  if (cnt == n)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
