#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool flag = true;
  int arr[n];
  memset(arr, -1, sizeof arr);
  for (int i = 0; i < m; i++) {
    int si, ci;
    cin >> si >> ci;
    if ((si == 1 && ci == 0) || (arr[si - 1] != -1 && arr[si - 1] != ci)) {
      flag = false;
      break;
    }
    arr[si - 1] = ci;
  }
  if (flag) {
    for (int i = 0; i < n; i++) {
      if (arr[i] == -1) arr[i] = 0;
    }
    int answer = 0;
    int y = 1;
    for (int i = n - 1; i >= 0; i--) {
      answer += arr[i] * y;
      y *= 10;
    }
    cout << answer << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}
