#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int a[3] = {};
  int b[3] = {};
  for (int i = 0; i < m; i++) {
    int q;
    cin >> q;
    b[q - 1]++;
    int p;
    cin >> p;
    if (n == 3 && p == 0 && q == 1) {
      cout << -1 << endl;
      return 0;
    }
    if (n == 2 && p == 0 && q == 2) {
      cout << -1 << endl;
      return 0;
    }
    if (a[q - 1] != p && b[q - 1] >= 2) {
      cout << -1 << endl;
      return 0;
    } else {
      a[q - 1] = p;
    }
  }
  if (n == 1) {
    cout << a[2] << endl;
  }
  if (n == 2) {
    if (a[1] == 0) {
      a[1] = 1;
    }
    cout << a[1] * 10 + a[2] << endl;
  }
  if (n == 3) {
    if (a[0] == 0) {
      a[0] = 1;
    }
    cout << a[0] * 100 + a[1] * 10 + a[2] << endl;
  }
}
