#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> d(n + 1, -1);
  bool can = true;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (d[s] != -1 && d[s] != c) {
      can = false;
      break;
    }
    d[s] = c;
  }
  int ans = 0;
  int undef_count = 0;
  for (int i = 1; i <= n; ++i) {
    if (d[i] == -1) undef_count++;
    if (i == n && d[i] == -1) {
      ans += pow(10, n - i);
    } else if (d[i] != -1) {
      ans += d[i] * pow(10, n - i);
    }
  }
  if (undef_count > m) can = false;
  cout << (can ? ans : -1) << endl;
}
