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