#include <bits/stdc++.h>
using namespace std;

int solver() {
  int n, m;
  cin >> n >> m;

  int num[n];
  for (int i = 0; i < n; i++) {
    num[i] = -1;
  }

  int minDigit = 1000000;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s-1] != c and num[s-1] != -1) {
      return -1;
    }
    if (minDigit > s) minDigit = s;
    num[s-1] = c;
  }
  if (m == 0) {
    return 0;
  }

  if (num[minDigit - 1] == 0) {
    if (minDigit == 1 and n != 1) return -1;
    if (minDigit > 1) num[min]
  }
  if (num[minDigit - 1] == 0 and minDigit > 1) num[minDigit - 2] = 1;

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (num[n-1-i] > 0) {
      ans += num[n-1-i] * pow(10, i);
    }
  }
  return ans;
}


int main() {
  int ans = solver();
  cout << ans << "\n";
  return 0;
}
