#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const long long P = 1000000007;
long long factorial(long long n) {
  long long ans = 1;
  for (int i = n; i >= 1; i--) {
    ans *= i;
    ans %= P;
  }
  return ans;
}
using Graph = vector<vector<int>>;
long long kzyou(long long a, long long k) {
  long long zyou = 1;
  for (long long i = 1; i <= k; i++) {
    zyou *= a;
  }
  return zyou;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> p[i].first >> p[i].second;
  }
  long long ketaN = kzyou(10, N - 1);
  sort(p.begin(), p.end());
  bool flag = true;
  for (int i = 0; i < M - 1; i++) {
    if (p[i].first == p[i + 1].first) {
      if (p[i].second != p[i + 1].second) flag = false;
    }
  }
  if (!flag) cout << -1 << endl;
  if (flag) {
    set<pair<int, int>> S;
    for (int i = 0; i < (int)(M); i++) {
      S.insert(p[i]);
    }
    int ans = 0;
    bool flag1 = false;
    for (auto value : S) {
      int k = value.first;
      int C = value.second;
      if (k == 1) flag1 = true;
      ans += kzyou(10, N - k) * C;
    }
    if (!flag1) ans += kzyou(10, N - 1);
    cout << ans << endl;
  }
}
