#include <bits/stdc++.h>
using namespace std;
inline unsigned long long read() {
  unsigned long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
void put1() { puts("Yes"); }
void put2() { puts("No"); }
void put3() { puts("-1"); }
unsigned long long qpf(unsigned long long a, unsigned long long b,
                       unsigned long long p) {
  unsigned long long ret = 0;
  while (b) {
    if (b & 1) ret = (ret + a) % p;
    a = (a + a) % p;
    b >>= 1;
  }
  return ret % p;
}
unsigned long long qp(unsigned long long a, unsigned long long n,
                      unsigned long long p) {
  unsigned long long ret = 1;
  while (n) {
    if (n & 1) ret = qpf(ret, a, p);
    a = qpf(a, a, p);
    n >>= 1;
  }
  return ret % p;
}
const int manx = 2e5 + 5;
int a[5];
int main() {
  unsigned long long n = read(), m = read();
  unsigned long long flag = 0;
  for (int i = 1; i <= m; i++) {
    unsigned long long x = read(), y = read();
    if (a[x] && a[x] != y)
      flag = 1;
    else
      a[x] = y;
  }
  unsigned long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0)
      ans += ans * 10 + a[i];
    else if (!a[i - 1])
      flag = 1;
    else
      ans *= 10;
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
