#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, a, b;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    if (ans[a - 1] != -1) {
      if (ans[a - 1] != b) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      ans[a - 1] = b;
    }
  }
  int ok = 0, x = 0;
  for (int i = 0; i < n; ++i) {
    if (ok == 0) {
      if (ans[i] == -1) {
        x *= 10;
        ++x;
      } else {
        x *= 10;
        x += ans[i];
        if (ans[i] == 0) {
          ok = 0;
          break;
        }
        ok = 1;
      }
    } else {
      if (ans[i] == -1) {
        x *= 10;
      } else {
        x *= 10;
        x += ans[i];
      }
    }
  }
  if (ok == 0) {
    cout << -1 << endl;
  } else {
    cout << x << endl;
  }
}
