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