#include <bits/stdc++.h>
using namespace std;
const double EPS = numeric_limits<double>::epsilon();
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  int N, M;
  cin >> N >> M;
  int result = -1;
  vector<int> stack(3, -1);
  int temp = 0;
  for (int(i) = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    if (stack[s - 1] == -1 || c < stack[s - 1]) {
      stack[s - 1] = c;
    }
  }
  for (int(i) = 0; i < (stack.size()); i++) {
    if (stack[i] == -1) {
      stack[i] = 0;
    }
    temp += pow(10, (N - (i + 1))) * stack[i];
  }
  int x = temp, count = 0;
  while (x > 0) {
    x /= 10;
    count++;
  }
  if (count == N) result = temp;
  cout << result << endl;
  return 0;
}
