#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
const int M = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int dig[n];
  for (int i = 0; i < n; i++) dig[i] = 0;
  while (m--) {
    int x, y;
    cin >> x >> y;
    x--;
    if (dig[x] > 0) {
      if (x > 0)
        dig[x] = min(dig[x], y);
      else if (x == 0 && y > 0)
        dig[x] = min(dig[x], y);
    } else if (dig[x] == 0)
      dig[x] = y;
  }
  if (dig[0] == 0 && n > 1) {
    return cout << -1, 0;
    ;
  }
  int num = 0;
  for (int i = 0; i < n; i++) {
    num = num * 10 + dig[i];
  }
  cout << num;
  return 0;
}
