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