#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> sc[5];
int nums[3];
int solve() {
  sort(sc, sc + m);
  int lasti = -1, lastn = -1;
  for (int i = 0; i < m; i++) {
    if (n != 1 && sc[i].first == 1 && sc[i].second == 0) return -1;
    if (sc[i].first == lasti && sc[i].second != lastn) return -1;
    nums[sc[i].first - 1] = sc[i].second;
    lasti = sc[i].first;
    lastn = sc[i].second;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += nums[i] * (int)pow(10, n - (i + 1));
  }
  return res;
}
int main() {
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> sc[i].first;
    cin >> sc[i].second;
  }
  printf("%d\n", solve());
}
