#include <bits/stdc++.h>
using namespace std;
int main() {
  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;
    s--;
    if (a[s] < 0 || a[s] == c) {
      a[s] = c;
    } else
      goto noans;
  }
  if (n != 1 && a[0] == 0) goto noans;
  for (int i = 0; i < n; i++) {
    ans = ans * 10 + max(a[i], 0);
  }
  cout << ans << endl;
  return 0;
noans:
  cout << -1 << endl;
}
