#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
template <typename T>
void printV(const std::vector<T>& v, const char* const separator = " ") {
  if (!v.empty()) {
    std::copy(v.begin(), --v.end(),
              std::ostream_iterator<T>(std::cout, separator));
    std::cout << v.back() << "\n";
  }
}
int64_t gcd(int64_t a, int64_t b) { return b != 0 ? gcd(b, a % b) : a; }
int64_t lcm(int64_t a, int64_t b) { return a / gcd(a, b) * b; }
int Max(int a, int b, int c) {
  int temp = max(a, b);
  return max(temp, c);
}
int Min(int a, int b, int c) {
  int temp = min(a, b);
  return min(temp, c);
}
bool integer(double num) { return floor(num) == num; }
int64_t fact(int num) {
  if (num == 0)
    return 1;
  else
    return num * fact(num - 1);
}
void y() {
  cout << "Yes"
       << "\n";
  exit(0);
}
void n() {
  cout << "No"
       << "\n";
  exit(0);
}
void Y() {
  cout << "YES"
       << "\n";
  exit(0);
}
void N() {
  cout << "NO"
       << "\n";
  exit(0);
}
int64_t yakusu(int n) {
  int cnt = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      cnt++;
      if (i * i != n) cnt++;
    }
  }
  return cnt;
}
int cnt = 0;
bool is_prime[50000 + 1];
vector<int> P;
void Eratosthenes(const int N) {
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
void euclid(int64_t N, int64_t a, int64_t b) {
  for (int64_t d = a + b; d <= N; d += b) {
    euclid(N, b, d);
  }
}
int64_t fact_mod(int64_t n, int64_t mod) {
  int64_t f = 1;
  for (int64_t(i) = (2); (i) <= (n); (i)++)
    f = f * (i % 1000000007) % 1000000007;
  return f;
}
int64_t mod_pow(int64_t x, int64_t n, int64_t mod) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
int64_t combination_mod(int64_t n, int64_t r, int64_t mod) {
  if (r > n - r) r = n - r;
  if (r == 0) return 1;
  int64_t a = 1;
  for (int64_t(i) = (0); (i) < (r); (i)++) a = a * ((n - i) % mod) % mod;
  int64_t b = mod_pow(fact_mod(r, mod), mod - 2, mod);
  return (a % mod) * (b % mod) % mod;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  std::cout << std::fixed << std::setprecision(15);
  ;
  int64_t a, b, n, k, x, m, y = 0, ans = 0;
  string str, t, u;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) cout << 0;
    if (n == 2) cout << 10;
    if (n == 3) cout << 100;
    cout << "\n";
    return 0;
  }
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int j = 0; j < m; ++j) {
    if (s[j] == 1 and c[j] == 0) {
      cout << -1 << "\n";
      return 0;
    }
  }
  int num[3] = {0, 0, 0};
  if (1 == 1) {
    for (int i = 0; i < m; ++i) {
      if (num[s[i] - 1] == 0 and c[i] == 0) {
        continue;
      }
      if (num[s[i] - 1] == 0 and c[i] != 0) {
        num[s[i] - 1] = c[i];
        continue;
      }
      if (num[s[i] - 1] != 0 and c[i] != num[s[i] - 1]) {
        cout << -1 << "\n";
        return 0;
      }
    }
  }
  if (num[0] == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (int l = 0; l < n; ++l) {
    cout << num[l];
  }
  cout << "\n";
  return 0;
}
