#include <bits/stdc++.h>
using namespace std;
long long int num[10];
int main(void) {
  long long int sum = 0, range = 0, ceiling;
  double ans = 0.0, d;
  long long int m, n, o, i, j, k = 1, money;
  long long int a, a1 = 0, a2 = 0, a3 = 0, ar = 1, as = 1, at1;
  string s;
  char c;
  a = a1 = a2 = a3 = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a1 >> a2;
    if (a1 == 1 && a2 == 0) {
      cout << "-1";
      return 0;
    }
    if (num[a1] == 0) {
      num[a1] = a2;
    } else {
      if (num[a1] != a2) {
        cout << "-1";
        return 0;
      }
    }
  }
  if (num[1] == 0) num[1] = 1;
  for (i = n; i > 0; i--) {
    sum += num[i] * ar;
    ar *= 10;
  }
  cout << sum;
  return 0;
}
