#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[10];
  memset(arr, -1, sizeof(arr));
  int mx = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (arr[a] != -1 && arr[a] != b) {
      cout << -1;
      return 0;
    }
    arr[a] = b;
    mx = max(mx, a);
  }
  if (mx > n || arr[1] == 0)
    cout << -1;
  else {
    for (int i = 1; i <= n; i++) {
      if (arr[i] == -1)
        cout << 0;
      else
        cout << arr[i];
    }
  }
}
