#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, M = 4;
int n, m;
int num[N];
int main() {
  cin >> n >> m;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (num[s] && num[s] != c) {
      puts("-1");
      return 0;
    } else
      num[s] = c;
  }
  int k = 1;
  while (k < n && !num[k]) k++;
  if (n - k + 1 == n) {
    for (int i = k; i <= n; i++) cout << num[i];
    puts("");
  } else
    puts("-1");
  return 0;
}
