#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  int ans = 1;
  scanf("%d %d", &n, &m);
  int sum = 0;
  vector<int> a(n + 1);
  int b, c;
  for (int i = 0; i < (m); ++i) {
    scanf("%d %d", &b, &c);
    if (a.at(b) == 0)
      a.at(b) = c;
    else if (a.at(b) != c)
      ans = 0;
  }
  bool zero = true;
  for (int i = 0; i < (a.size()); ++i) {
    if (a.at(i) != 0) zero = false;
    if (zero && i == 1) ans = 0;
    sum += a.at(i) * pow(10, (n - i));
  }
  if (ans == 1)
    printf("%d\n", sum);
  else
    printf("%d\n", -1);
}
