#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
using pii = pair<int, int>;
int N, M;
int nums[100];
int main() {
  memset(nums, -1, sizeof nums);
  cin >> N >> M;
  while (M--) {
    int a, b;
    cin >> a >> b;
    if (nums[a] != -1 && nums[a] != b) {
      puts("-1");
      return 0;
    }
    nums[a] = b;
  }
  if (N > 1 && (nums[1] == -1 || nums[1] == 0)) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (nums[i] != -1)
      cout << nums[i];
    else
      cout << 0;
  }
  return 0;
}
