#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
bool IsPrime(long long int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (long long int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) return false;
  }
  return true;
}
long long int GetDigit(long long int num) { return log10(num) + 1; }
long long int KSum(long long int n) {
  long long int sum = 0;
  if (n < 0) return 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
bool KReve(long long int n) {
  int reverse = 0;
  int remaind;
  int tmp = n;
  while (tmp != 0) {
    remaind = tmp % 10;
    reverse = reverse * 10 + remaind;
    tmp /= 10;
  }
  if (reverse == n)
    return true;
  else
    return false;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
long long int factorial(long long int n) {
  long long int a = 1;
  long long int b = n;
  for (int i = 0; i < n; i++) {
    a *= b;
    b--;
  }
  return a;
}
long long int comb(long long int a, long long int b) {
  long long int c;
  c = factorial(a) / (factorial(a - b) * factorial(b));
  return c;
}
long long int sigma(long long int n, long long int m) {
  return ((n + m) * (m - n + 1) * 0.5);
}
long double hope(long double a) { return (sigma(1, a) / a); }
int main(void) {
  ios::sync_with_stdio(false);
  long long int N;
  cin >> N;
  long long int M;
  cin >> M;
  vector<long long int> s(M), c(M);
  for (long long int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  };
  map<long long int, long long int> S;
  long double ans = 0;
  long long int A = 0;
  for (long long int i = 0; i < M; i++) {
    if (S.count(s[i])) {
      if (S[s[i]] < c[i]) {
        S[s[i]] = c[i];
      }
    } else {
      S[s[i]] = c[i];
      ans = S[s[i]] * pow(10, N - s[i]);
      A += ans;
    }
  }
  if (GetDigit(A) == N) {
    cout << A << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
