#include <bits/stdc++.h>
using namespace std;
int C[3];
int main() {
  for (int i = 0; i < 3; i++) {
    C[i] = -1;
  }
  bool flag = true;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0 && n != 1) {
      flag = false;
      break;
    }
    if (C[s] != -1 && C[s] != c) {
      flag = false;
      break;
    } else {
      C[s] = c;
    }
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (C[i] == -1) {
      C[i] = (i == 0) ? 1 : 0;
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += C[i] * pow(10, n - i - 1);
  }
  cout << sum << endl;
  return 0;
}
