#include <bits/stdc++.h>
using namespace std;
long long modpow(long long x, long long y,
                 long long m = (long long)(1000000007)) {
  long long res = 1;
  while (y) {
    if (y % 2) {
      res *= x;
      res %= m;
    }
    x = x * x % (long long)(1000000007);
    y /= 2;
  }
  return res;
}
long long mypow(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2) {
      res *= x;
    }
    x = x * x;
    y /= 2;
  }
  return res;
}
bool prime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (!(x % i)) {
      return false;
    }
  }
  return true;
}
inline long long gcd(long long x, long long y) {
  if (!y) {
    return x;
  }
  return gcd(y, x % y);
}
long long keta(long long x) {
  long long ans = 0;
  while (x) {
    x /= 10;
    ans++;
  }
  return ans;
}
long long ketasum(long long x) {
  long long ans = 0;
  while (x) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
inline long long lcm(long long x, long long y) {
  long long ans = x / gcd(x, y) * y;
  return ans;
}
long long twobeki(long long x) {
  long long ans = 0;
  while (1) {
    if (!(x & 1)) {
      ans++;
      x /= 2;
    } else {
      break;
    }
  }
  return ans;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
long long n, m, s[10], c[10], ans;
long long did[10];
bool did2[10];
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && (!c[i])) {
      cout << -1 << endl;
      return 0;
    }
    if (did2[s[i]]) {
      if (did[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      } else {
        continue;
      }
    }
    did2[s[i]] = 1;
    did[s[i]] = c[i];
    ans += mypow(10, n - s[i]) * c[i];
  }
  cout << ans << endl;
}
