#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int num[n];
  for (int i = 0; i < n; i++) {
    num[i] = 0;
  }
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (num[s - 1] != 0 && c != num[s - 1]) {
      cout << "-1" << endl;
      return 0;
    } else {
      num[s - 1] = c;
    }
  }
  int number = 0;
  for (int i = 0; i < n; i++) {
    number += num[i] * ceilf(pow(10, n - i - 1));
  }
  if (number < pow(10, n - 1)) {
    if (number == 0 && n == 1) {
      cout << number << endl;
      return 0;
    }
    cout << "-1" << endl;
    return 0;
  }
  cout << number << endl;
}
