#include <bits/stdc++.h>
using namespace std;
set<int> s;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) a[i] = 0;
  while (m--) {
    int idx, val;
    cin >> idx >> val;
    a[idx - 1] = val;
  }
  string ans = "-1";
  for (int i = 0; i < n; i++) {
    if (i != n - 1 && a[i] == 0) {
      cout << ans;
      return 0;
    }
    ans += a[i];
  }
  cout << ans << endl;
}
