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