#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using P = pair<long long, long long>;
const int INF = 1001001001;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int MAX = 500010;
const int MOD = 1000000007;
bool comInit;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long com(long long n, long long k) {
  if (!comInit) {
    cominit();
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long moddiv(long long x, long long y, long long mod) {
  y = modpow(y, mod - 2, mod);
  return x * y % mod;
}
long long modcomb(long long n, long long r, long long mod) {
  long long x = 1;
  long long y = 1;
  for (long long i = 0; i < (long long)(r); i++) {
    x = (x * (n - i)) % mod;
    y = (y * (i + 1)) % mod;
  }
  return moddiv(x, y, mod);
}
struct uf {
  vector<long long> par;
  vector<long long> sizes;
  uf(int n) {
    for (int i = 0; i < n; i++) {
      par.push_back(i);
      sizes.push_back(1);
    }
  }
  long long root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    sizes[ry] = sizes[rx] + sizes[ry];
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  long long size(int x) { return sizes[root(x)]; }
};
class Radix {
 private:
  const char* s;
  int a[128];

 public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for (i = 0; s[i]; ++i) a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if (!p) return "0";
    char t[64] = {};
    for (i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) { return to(to(t, p), q); }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]];
    return sm;
  }
};
struct node {
 public:
  long long x;

 public:
  long long y;
  node(long long xx, long long yy) {
    x = xx;
    y = yy;
  }
};
bool initComb;
std::vector<std::vector<long long>> combC;
long long comb(int n, int r) {
  if (!initComb) {
    combC =
        vector<std::vector<long long>>(n + 1, std::vector<long long>(n + 1, 0));
    for (int i = 0; i < combC.size(); i++) {
      combC[i][0] = 1;
      combC[i][i] = 1;
    }
    for (int j = 1; j < combC.size(); j++) {
      for (int k = 1; k < j; k++) {
        combC[j][k] = (combC[j - 1][k - 1] + combC[j - 1][k]);
      }
    }
    initComb = true;
  }
  return combC[n][r];
}
long long digit(long long num) {
  if (num < 10) {
    return 1;
  }
  long long d = 1;
  long long k = 10;
  while (num >= k) {
    d++;
    k *= 10;
  }
  return d;
}
long long digitNum(long long num, long long count) {
  long long a = (num % (long long)pow((double)10, (double)count));
  return a / pow(10, count - 1);
}
bool less_abs(int lhs, int rhs) {
  if (lhs < 0) {
    lhs *= -1;
  }
  if (rhs < 0) {
    rhs *= -1;
  }
  return lhs < rhs;
}
bool IsTrueBit(int bit, int index) { return (bit & (1 << index)); }
int main() {
  long long n, m;
  cin >> n >> m;
  P p[m];
  for (long long i = 0; i < (long long)(m); i++) {
    long long s, c;
    cin >> s >> c;
    p[i] = P(s, c);
  }
  map<long long, long long> mm;
  for (long long i = 0; i < (long long)(10); i++) {
    mm[i] = -1;
  }
  for (long long i = 0; i < (long long)(m); i++) {
    if (p[i].first > n) {
      cout << -1 << endl;
      return 0;
    }
    if (p[i].first == 1 && p[i].second == 0 && n > 1) {
      cout << -1 << endl;
      return 0;
    }
    if (mm[p[i].first] >= 0 && mm[p[i].first] != p[i].second) {
      cout << -1 << endl;
      return 0;
    }
    mm[p[i].first] = p[i].second;
  }
  vector<char> v;
  for (long long i = 0; i < (long long)(n); i++) {
    v.push_back('0');
  }
  for (long long i = 0; i < (long long)(m); i++) {
    char c = '0' + p[i].second;
    v[p[i].first - 1] = c;
  }
  string g = "";
  for (long long i = 0; i < (long long)(n); i++) {
    if (i == 0 && v[i] == '0') {
      g = g + '1';
    } else {
      g = g + v[i];
    }
  }
  cout << g << endl;
  return 0;
}
