#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[3] = {0, 0, 0};
  bool flag = true;
  int n, m, x, y, num = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (s[x - 1] != 0 && s[x - 1] != y) flag = false;
    s[x - 1] = y;
  }
  for (int i = 0; i < n; i++) {
    num += (int)pow(10, i) * s[n - i - 1];
  }
  if (num == 0 || s[0] == 0) {
    flag = false;
  }
  if (flag) {
    cout << num << "\n";
  } else {
    cout << "-1"
         << "\n";
  }
}
