#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, s, c;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < (m); i++) {
    cin >> s >> c;
    s--;
    if (n != 1 && s == 0 && c == 0) {
      ans[0] = -2;
      break;
    } else if (ans[s] != -1 && ans[s] != c) {
      ans[0] = -2;
      break;
    } else {
      ans[s] = c;
    }
  }
  if (ans[0] == -2)
    cout << -1 << endl;
  else {
    int sum = 0, o = 1;
    for (int i = 0; i < (n); i++) {
      if (i == 0 && ans[i] == -1 && n != 1)
        ans[i] = 1;
      else if (ans[i] == -1)
        ans[i] = 0;
      sum += ans[n - 1 - i] * o;
      o *= 10;
    }
    cout << sum << endl;
  }
  return 0;
}
