#include <bits/stdc++.h>
using namespace std;
using long long int = long long int;
using pii = pair<int, int>;
using pll = pair<long long int, long long int>;
using vi = vector<int>;
using vl = vector<long long int>;
using vii = vector<pii>;
using vll = vector<pll>;
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vi num(N, -1);
  int ans = 0;
  int s, c;
  for (long long int i = 0; i < M; i++) {
    scanf("%d%d", &s, &c);
    s--;
    if (s == 0 && c == 0) ans = -1;
    if (num[s] != -1 && num[s] != c) ans = -1;
    num[s] = c;
  }
  if (ans != -1) {
    ans += num[0] >= 0 ? num[0] : 1;
    for (long long int i = 1; i < N; i++) {
      ans *= 10;
      ans += num[i] >= 0 ? num[i] : 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
