#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; ++i) res = res * i;
  return res;
}
long long nCr(long long n, long long r) {
  return (fact(n) / fact(n - r) * fact(r));
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const int inf = 1000100011;
int N, M;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  vector<int> sum(N);
  for (int i = 0; i < (int)(N); ++i) sum[i] = -1;
  vector<int> s(N), c(N);
  for (int i = 0; i < (int)(M); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
    if ((sum[s[i]] != -1 && sum[s[i]] != c[i]) || s[i] > N) {
      cout << -1 << endl;
      return 0;
    }
    sum[s[i]] = c[i];
  }
  vector<int> ans(N);
  for (int i = 0; i < (int)(N); ++i) {
    if (sum[i] != -1) {
      ans[i] = sum[i];
    } else {
      ans[i] = 0;
    }
  }
  int zeroNum = 0;
  for (int i = 0; i < (int)(N); ++i) {
    if (ans[i] == 0) zeroNum += 1;
  }
  if (zeroNum == N && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(N); ++i) cout << ans[i];
  cout << endl;
  return 0;
}
