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