#include <bits/stdc++.h>
using namespace std;
namespace math {
long double PI = 3.14159265359;
long long step(long long n);
long long ncr(long long n, long long r);
long long npr(long long n, long long r);
long long gcm(long long a, long long b);
long long lcm(long long a, long long b);
long long step(long long n) {
  if (n <= 1) {
    return 1;
  } else {
    return n * step(n - 1);
  }
}
long long ncr(long long n, long long r) {
  for (long long i = 1; i < r; i++) {
    n *= n - i;
  }
  for (long long i = 1; i < r; i++) {
    r *= r - 1;
  }
  return n / r;
}
long long npr(long long n, long long r) {
  for (long long i = 1; i < r; ++i) {
    n *= n - 1;
  }
  return n;
}
long long gcm(long long a, long long b) {
  long long p = max(a, b);
  long long q = min(a, b);
  long long r;
  while (true) {
    if (p % q == 0) {
      return q;
    }
    r = p % q;
    p = q;
    q = r;
  }
}
}  // namespace math
using namespace std;
namespace tmp {
template <typename T>
bool inArry(T x, vector<T> v);
template <typename T>
bool inArry(T x, vector<T> v) {
  long long l = v.size();
  for (long long i = 0; i < l; i++) {
    if (x == v[i]) {
      return true;
    }
  }
  return false;
}
}  // namespace tmp
using namespace std;
signed main() {
  long long ans = 0;
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> sc(m);
  vector<long long> num(n, 0);
  long long flag = 0;
  long long digit = 0;
  for (long long((i)) = 0; (i) < (1) * ((m)); ((i)) += (1)) {
    cin >> sc.at(i).first >> sc.at(i).second;
    num[sc[i].first - 1] = sc[i].second;
  }
  for (long long((i)) = 0; (i) < (1) * ((m)); ((i)) += (1)) {
    if (num[sc[i].first - 1] != sc[i].second) {
      flag = 1;
    }
  }
  if (m > 1) {
    if (num[0] == 0) {
      flag = 1;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    long long ans = 0;
    for (long long((i)) = 0; (i) < (1) * ((n)); ((i)) += (1)) {
      ans += num[i] * pow(10, m - 1 - i);
    }
    cout << ans << endl;
  }
  return 0;
}
