#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 6;
int arr[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  memset(arr, 0, sizeof(arr));
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (b == 0)
      arr[a - 1] = -2;
    else
      arr[a - 1] = b;
  }
  if (n == 1 and arr[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == 0)
      arr[i] = -1;
    else
      break;
  }
  int lead = 1;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0 and lead) {
      cout << -1 << endl;
      break;
    } else {
      if (arr[i] != -1) {
        if (arr[i] == -2)
          cout << 0;
        else
          cout << arr[i];
        lead = 0;
      }
    }
  }
}
