#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int arr[m][2];
  for (int i = 0; i < m; i++) cin >> arr[i][0] >> arr[i][1];
  int num[n];
  for (int i = 0; i < n; i++) num[i] = -1;
  int flag = 0;
  for (int i = 0; i < m; i++) {
    if ((num[arr[i][0] - 1] != -1 && arr[i][1] != num[arr[i][0] - 1]) ||
        (arr[i][0] == 1 && arr[i][1] == 0) || arr[i][0] - 1 > n)
      flag = 1;
    else
      num[arr[i][0] - 1] = arr[i][1];
  }
  int flag2 = 0;
  for (int i = 0; i < n; i++) {
    if (flag2 == 0 && num[i] == 0)
      flag = 1;
    else if (num[i] != 0)
      flag2 = 1;
  }
  if (flag == 1)
    cout << -1;
  else {
    flag = 0;
    for (int i = 0; i < n; i++) {
      if (i == 0 && num[i] == -1) {
        cout << 1;
      } else if (flag == 1 && num[i] == -1)
        cout << 0;
      else
        cout << num[i];
    }
  }
}
