#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[10] = {-1};
  int s, c;
  int sum = 0;
  cin >> n >> m;
  if (n == 1 && !m) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s] == -1)
      if (a[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    a[s] = c;
  }
  for (int i = 1; i <= 3; i++) {
    if (a[i] != -1) {
      sum += a[i] * int(pow(10, n - i) + 0.5);
    }
  }
  if (n > 1 && a[1] == 0 || n > 1 && a[1] == 0 && a[2] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n > 1 && a[1] == -1) {
    sum += 1 * int(pow(10, n - s) + 0.5);
  }
  cout << sum << endl;
  return 0;
}
