#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
long long Gcd(long long a, long long b) {
  if (a < b) {
    return Gcd(b, a);
  }
  if (b == 0) {
    return a;
  } else {
    return Gcd(b, a % b);
  }
}
long long Lcm(long long a, long long b) {
  long long abd = Gcd(a, b);
  long long x = a / abd, y = b / abd;
  return x * y * abd;
}
long long RepSqu(long long N, long long P, long long M) {
  if (P == 0) {
    return 1;
  }
  if (P % 2 == 0) {
    long long t = RepSqu(N, P / 2, M);
    return t * t % M;
  }
  return (N * RepSqu(N, P - 1, M)) % M;
}
int main() {
  int N, M;
  bool t = false;
  cin >> N >> M;
  vector<int> A(N);
  vector<bool> B(N);
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    if (s > N) {
      t = true;
      break;
    }
    if (B.at(s - 1)) {
      if (c != A.at(s - 1)) {
        t = true;
        break;
      }
    }
    A.at(s - 1) = c;
    B.at(s - 1) = true;
  }
  if (N != 1 && A.at(0) == 0) {
    t = true;
  }
  if (t)
    cout << -1 << endl;
  else {
    for (int i = (0); i < (N); ++i) {
      cout << A.at(i);
    }
    cout << endl;
  }
}
