#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = INT_MAX;
long long int lcm(long long int a, long long int b) {
  long long int lcm = a * b;
  long long int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return lcm /= b;
}
long long int gcd(long long int a, long long int b) {
  long long int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
long long int modadd(long long int a, long long int b) {
  return (a % MOD + b % MOD + MOD) % MOD;
}
long long int modmul(long long int a, long long int b) {
  return a % MOD * b % MOD % MOD;
}
long long int modexp(long long int a, long long int n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    long long int e = modexp(a, n / 2);
    return modmul(e, e);
  }
  return modexp(a, n - 1) * a % MOD;
}
long long int modinv(long long int n) { return modexp(n % MOD, MOD - 2); }
long long int modfact(long long int n) {
  long long int res = 1;
  for (int i = 1; i <= n; ++i) {
    res *= i;
    res %= MOD;
  }
  return res;
}
long long int modncr(long long int n, long long int r) {
  long long int numer = 1;
  long long int denom = 1;
  for (int i = 1; i <= r; ++i) {
    numer = modmul(numer, n - r + i);
    denom = modmul(denom, i);
  }
  return modmul(numer, modinv(denom));
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < (m); ++i) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  int ans[n + 1];
  for (int i = 0; i < (n + 1); ++i) ans[i] = 0;
  if (n == 1) {
    ans[1] = 0;
  } else {
    ans[1] = 1;
  }
  bool exist = true;
  for (int i = 0; i < (m); ++i) {
    ans[p[i].first] = p[i].second;
    if (i < m - 1) {
      if (p[i].first == p[i + 1].first && p[i].second != p[i + 1].second) {
        exist = false;
      }
    }
  }
  if (ans[1] == 0 && 2 <= n) {
    exist = false;
  } else if (exist) {
    bool flag = false;
    for (int i = 1; i <= n; ++i) {
      cout << ans[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
