#include <bits/stdc++.h>
using namespace std;
int num[5];
int main() {
  memset(num, -1, sizeof(num));
  int n, m, i, x, y;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (num[x] != -1 && num[x] != y || x == 1 && !y) {
      cout << -1;
      return 0;
    }
    num[x] = y;
  }
  if (n == 1 && num[1] == -1) {
    cout << 0;
    return 0;
  }
  if (num[1] == -1)
    cout << 1;
  else
    cout << num[1];
  for (i = 2; i <= n; i++)
    if (num[i] == -1)
      cout << 0;
    else
      cout << num[i];
  return 0;
}
