#include <bits/stdc++.h>
using namespace std;
int DivUp(long long a, long long b) { return (a + (b - 1) / b); }
int main() {
  int n, m;
  bool isAlreadyIncludeOne = false;
  cin >> n >> m;
  vector<int> s(m), c(m), ans(n);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  if (n == 1) {
    for (int i = 0; i < n; i++) {
      if (c[i] == 0) cout << c[i] << endl;
      return 0;
    }
  }
  if (n >= 1) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && c[i] != 0 && !isAlreadyIncludeOne) {
        isAlreadyIncludeOne = true;
        ans[0] = c[i];
      }
    }
  }
  if (!isAlreadyIncludeOne) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1) continue;
    if (ans[s[i] - 1] == 0) ans[s[i] - 1] = c[i];
  }
  for (int i = 0; i < n; i++) cout << ans[i];
  cout << endl;
  return 0;
}
