#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int INF = (int)1e9 + 5;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> aa(n + 1, 10);
  while (m--) {
    int a, b;
    cin >> a >> b;
    aa[a] = min(aa[a], b);
  }
  if (aa[1] == 10 || aa[1] == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (aa[i] == 10) {
      cout << 0;
    } else {
      cout << aa[i];
    }
  }
  cout << "\n";
  return 0;
}
