#include <bits/stdc++.h>
using namespace std;
long long int mpow(long long int x, long long int n);
int main(void);
__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
long long int mpow(long long int x, long long int n) {
  long long int ans = 1;
  while (n >= 1) {
    if (n % 2 == 0) {
      x = x * x % (long long int)(1e9 + 7);
      n = n / 2;
    } else {
      ans = ans * x % (long long int)(1e9 + 7);
      n = n - 1;
    }
  }
  return ans;
}
int main(void) {
  long long int N, M;
  vector<long long int> s, c;
  vector<pair<long long int, long long int>> p;
  cin >> N >> M;
  if (M == 0) {
    long long int ans = mpow(10, N - 1);
    if (ans == 1) ans = 0;
    cout << ans << endl;
  } else {
    for (int i = 0; i < (int)(M); i++) {
      long long int s0, c0;
      pair<long long int, long long int> p0;
      cin >> s0 >> c0;
      s.push_back(s0);
      c.push_back(c0);
      p.push_back(make_pair(s0, c0));
    }
    long long int ans = 0;
    sort(p.begin(), p.end());
    long long int max = p[M - 1].first;
    if (p[0].first > 1) ans += mpow(10, N - 1);
    long long int fir = 0;
    long long int sec = 0;
    for (int i = 0; i < (int)(M); i++) {
      if (p[i].first == fir && p[i].second != sec) {
        ans = -1;
        break;
      }
      if (p[i].first == 1 && p[i].second == 0) {
        ans = -1;
        break;
      }
      if (p[i].first > fir) {
        ans += p[i].second * mpow(10, N - p[i].first);
      }
      fir = p[i].first;
      sec = p[i].second;
    }
    cout << ans << endl;
  }
  return 0;
}
