#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int mypow(int a, int b) {
  int num = 1;
  while (b != 0) {
    num *= a;
    b--;
  }
  return num;
}
int main() {
  int n, m, i;
  cin >> n >> m;
  int ans = 0;
  vector<int> distin(n + 1, -1);
  for (i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (distin[s] != -1 && c != distin[s]) {
      cout << -1 << endl;
      return 0;
    }
    distin[s] = c;
  }
  if (n != 1 && distin[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    if (distin[i] != -1) {
      ans += (mypow(10, n - i) * distin[i]);
    }
  }
  int keta = 0, num = ans;
  while (num != 0) {
    keta++;
    num /= 10;
  }
  if (keta != n) {
    ans += (mypow(10, n - 1));
  }
  cout << ans << endl;
  return 0;
}
