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