#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  bool ok = true;
  for (int i = 0; i < m; ++i) {
    int pos, c;
    cin >> pos >> c;
    pos--;
    if (pos == 0 && c == 0 && n > 1) ok = false;
    if (ans[pos] != -1 && ans[pos] != c) ok = false;
    ans[pos] = c;
  }
  if (!ok) {
    cout << "-1\n";
    return 0;
  }
  if (n > 0 && ans[0] == -1) ans[0] = 1;
  for (int i = 0; i < n; ++i) cout << (ans[i] == -1 ? 0 : ans[i]);
  cout << endl;
}
