#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n, 1);
  return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
const ll INF = LONG_MAX;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main(int argc, char* argv[]) {
  int n, m;
  cin >> n >> m;
  int s[10], c[10];
  for (int i = 0; i < (int)m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (int)m; i++) {
    for (int j = 0; j < (int)m; j++) {
      if ((s[i] == s[j]) && (c[i] != c[j])) {
        cout << "-1";
        return 0;
      }
    }
  }
  int ans[10] = {0};
  int ret = 0;
  for (int i = int(1); i < int(n + 1); ++i) {
    for (int si = 0; si < (int)m; si++) {
      if (i == s[si]) {
        ans[i] = c[si];
      }
    }
  }
  for (int i = int(1); i < int(n + 1); ++i) {
  }
  for (int i = int(1); i < int(n + 1); ++i) {
    ret += ans[i] * pow(10, (n - i));
  }
  if (n != 1) {
    if (ret < pow(10, n - 1)) {
      cout << "-1";
      return 0;
    }
  }
  cout << ret;
  return 0;
}
