#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;
  map<int, int> stack;
  bool is_exist = true;
  int temp = 0;
  for (int(i) = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    auto itr = stack.find(s);
    if (itr == stack.end()) {
      temp += pow(10, (N - s)) * c;
      stack[s]++;
    }
  }
  int x = temp, count = 0;
  while (x > 0) {
    x /= 10;
    count++;
  }
  if (count == N) result = temp;
  cout << result << endl;
  return 0;
}
