#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 public:
  vector<int> Parent;
  UnionFind(int N) { Parent = vector<int>(N, -1); }
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  int size(int A) { return -Parent[root(A)]; }
  bool connect(int A, int B) {
    A = root(A);
    B = root(B);
    if (A == B) {
      return false;
    }
    if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};
template <typename T>
struct SegTree {
  using F = function<T(T, T)>;
  vector<T> seg;
  int siz;
  const T unit;
  const F f;
  SegTree(int n, const T unit, const F f) : unit(unit), f(f) {
    siz = 1;
    while (siz < n) siz <<= 1;
    seg.assign(siz * 2 - 1, unit);
    siz--;
  }
  void set(int k, const T& t) { seg[k + siz] = t; }
  void build() {
    for (int i = siz - 1; 0 <= i; i--) {
      seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]);
    }
  }
  T operator[](const int i) { return seg[i + siz]; }
  void update(int k, T x) {
    k += siz;
    seg[k] = x;
    while (0 < k) {
      k = (k - 1) >> 1;
      seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  T query(int a, int b) {
    T l = unit, r = unit;
    for (a += siz, b += siz; a < b; a >>= 1, b >>= 1) {
      if (!(a & 1)) l = f(seg[a++], l);
      if (!(b & 1)) r = f(seg[--b], r);
    }
    return f(l, r);
  }
};
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
template <typename T>
bool check(T a, T b) {
  return a < b;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long int convination(long long int a, long long int b) {
  long long int ans = 1;
  for (long long int i = 0; i < b; i++) {
    ans *= a - i;
    ans %= 1000000007;
  }
  for (long long int i = 1; i <= b; i++) {
    ans *= modinv(i, 1000000007);
    ans %= 1000000007;
  }
  return ans;
}
long long int power(long long int a, long long int b) {
  if (b == 1) return a;
  if (b == 0) return 1;
  long long int tmp = power(a, (long long int)b / 2);
  tmp *= tmp;
  tmp %= long long int(1e9 + 7);
  if (b % 2 == 1) {
    tmp *= a;
    tmp %= long long int(1e9 + 7);
  }
  return tmp;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n, -1);
  int m;
  cin >> m;
  bool ans = true;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x - 1] == -1 || a[x - 1] == y)
      a[x - 1] = y;
    else
      ans = false;
  }
  if (ans && a[0] != 0) {
    for (int i = 0; i < n; i++) {
      if (a[i] < 0)
        cout << 0;
      else
        cout << a[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
