#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, s, c;
  cin >> n >> m;
  int num[n];
  memset(num, -1, sizeof num);
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (num[s - 1] != -1 && c) {
      num[s - 1] = min(num[s - 1], c);
    } else if (c)
      num[s - 1] = c;
  }
  if (num[0] < 1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (num[i] == -1)
      cout << 0;
    else
      cout << num[i];
  }
}
