#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  for (int i = 0; i < m; i++) {
    int d, c;
    cin >> d >> c;
    --d;
    if (s[d] > 0 && s[d] != c) return cout << -1 << endl, 0;
    s[d] = c;
  }
  if (n != 1 && !s[0]) return cout << -1 << endl, 0;
  int ans = 0;
  for (auto x : s) ans = ans * 10 + x;
  cout << ans << endl;
}
