#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int a = 1, N, M, s, c, tmp = 0;
  cin >> N >> M;
  vector<long long int> ans(N), flag(N);
  for (long long int i = 0, i_len = (N); i < i_len; i++) {
    ans[i] = 0;
    flag[i] = 0;
  }
  for (long long int i = 0, i_len = (M); i < i_len; i++) {
    cin >> s >> c;
    a = 1;
    for (long long int j = 0, j_len = (N - s); j < j_len; j++) {
      a = a * 10;
    }
    tmp = c * a;
    if (flag[s - 1] == 1) {
      continue;
    } else if (tmp == 0 && s - 1 != 0) {
      ans[s - 1] = tmp;
      flag[s - 1] = 1;
    } else if ((ans[s - 1] > tmp || ans[s - 1] == 0)) {
      ans[s - 1] = tmp;
    }
  }
  tmp = 0;
  for (long long int i = 0, i_len = (N); i < i_len; i++) {
    tmp += ans[i];
  }
  a = 1;
  for (long long int i = 0, i_len = (N - 1); i < i_len; i++) {
    a = a * 10;
  }
  if (tmp / a != 0) {
    cout << tmp << '\n';
  } else if (tmp == 0 && N == 1) {
    cout << 0 << '\n';
  } else {
    cout << -1 << '\n';
  }
}
