#include <bits/stdc++.h>
using namespace std;
int digit[4];
int main() {
  int n, m;
  cin >> n >> m;
  int fac = 0;
  memset(digit, -1, sizeof(digit));
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0) {
      fac = 1;
      cout << m << endl;
    } else if (digit[a] != -1 && digit[a] != b) {
      fac = 1;
      cout << m << endl;
    } else
      digit[a] = b;
  }
  if (fac)
    cout << -1 << endl;
  else {
    int ans = 0;
    if (digit[1] == -1)
      ans += pow(10, n - 1);
    else
      ans += digit[1] * pow(10, n - 1);
    if (digit[2] != -1) ans += digit[2] * pow(10, n - 2);
    if (digit[3] != -1) ans += digit[3] * pow(10, n - 3);
    cout << ans << endl;
  }
  return 0;
}
