#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7LL;
const int INF = 2e9;
int N, M;
int s[10], c[10];
vector<pair<int, int> > a;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    a.push_back(pair<int, int>(s[i], c[i]));
  }
  sort((a).begin(), (a).end());
  int now = 0;
  int idx = 0;
  int th = 0;
  for (int i = 0; i < M; ++i) {
    if (a[i].first && a[i].second == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (a[i].first != now) {
      now = a[i].first;
      idx = i;
      th = a[i].second;
      continue;
    }
    if (th != a[i].second) {
      cout << -1 << "\n";
      return 0;
    }
    a.erase(a.begin() + idx);
  }
  int ans = 0;
  for (int i = 0; i < a.size(); ++i) {
    ans += a[i].second * pow(10, N - a[i].first);
  }
  if (a[0].first != 1) {
    ans += 1 * pow(10, N - 1);
  }
  cout << ans << "\n";
  return 0;
}
