#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long maxn = 1e2 + 5;
const int MOD = 1e9 + 7;
const double exps = 1e-6;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, cn[10], cm[10], ans[3] = {10, 10, 10};
  cin >> n >> m;
  int x, y;
  bool flag = false;
  for (int i = (0); i < (m); ++i) {
    cin >> x >> y;
    if (ans[x - 1] != 10 && ans[x - 1] != y) flag = true;
    ans[x - 1] = min(y, ans[x - 1]);
  }
  if (ans[0] == 0 && n != 1 || flag)
    cout << -1;
  else {
    for (int i = (0); i < (n); ++i) {
      if (i == 0 && ans[i] == 10)
        cout << 1;
      else if (ans[i] == 10)
        cout << 0;
      else
        cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}
