#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> num(n);
  num[n - 1].first = 1;
  for (int i = 0; i < (n - 1); ++i) num[i].first = 0;
  for (int i = 0; i < (n); ++i) num[i].second = 0;
  int out = 0;
  int s, c;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if ((s == 1) && (c == 0)) {
      out = 1;
      break;
    }
    if (num[n - s].second == 0) {
      num[n - s].first = c;
      num[n - s].second = 1;
    } else {
      out = 1;
      break;
    }
  }
  if (out == 1)
    cout << -1 << endl;
  else {
    int ans = num[n - 1].first;
    for (int j = n - 2; j >= 0; --j) ans = 10 * ans + num[j].first;
    cout << ans << endl;
  }
}
