#include <bits/stdc++.h>
using namespace std;
static const long long llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const long long llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const long long d_5 = 100000;
static const long long d9_7 = 1000000007;
static const long long d_9 = 1000000000;
static const double PI = 3.14159265358979323846;
template <class T>
void Printvector(std::vector<T> a) {
  int size = a.size();
  for (int i = 0; i < size; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class T>
void Printvector(std::vector<std::vector<T>> a) {
  int size = a.size();
  for (int i = 0; i < size; i++) {
    int size2 = a[i].size();
    for (int j = 0; j < size2; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
long long digitpower(long long a, long long b) {
  if (b == 1) {
    return a;
  } else if (b == 0) {
    return 1;
  }
  int mode = 1;
  if (b % 2 == 1) {
    long long tmp = digitpower(a, (b - 1) / 2);
    if (mode == 1) {
      tmp %= d9_7;
    }
    tmp *= tmp;
    if (mode == 1) {
      tmp %= d9_7;
    }
    tmp *= a;
    if (mode == 1) {
      return tmp % d9_7;
    } else {
      return tmp;
    }
  } else {
    long long tmp = digitpower(a, (b) / 2);
    if (mode == 1) {
      tmp %= d9_7;
    }
    tmp *= tmp;
    if (mode == 1) {
      tmp %= d9_7;
    }
    if (mode == 1) {
      return tmp % d9_7;
    } else {
      return tmp;
    }
  }
}
vector<long long> facs(2000010, -1);
long long Factrial(long long num) {
  if (facs[num] != -1) {
    return facs[num];
  }
  if (num == 1 || num <= 0) {
    return 1;
  } else if (num < 0) {
    printf("ERROR_minus\n");
    return 0;
  } else {
    facs[num] = (num * Factrial(num - 1)) % d9_7;
    return facs[num];
  }
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
vector<long long> invs(2000010, -1);
long long linercomb(long long n, long long k, long long mod) {
  if (n < k) return 0;
  if (n < 0) return 0;
  if (k == 0 || k == n) return 1;
  long long ans = Factrial(n);
  if (invs[k] == -1) {
    invs[k] = modinv(Factrial(k), mod);
  }
  ans *= invs[k];
  ans %= d9_7;
  long long k1 = Factrial(n - k);
  k1 %= mod;
  ans *= modinv(k1, mod);
  ans %= mod;
  return ans;
}
unordered_map<long long, long long> prime_factor(int64_t n) {
  unordered_map<long long, long long> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
template <class T>
vector<T> getaccum(vector<T> a) {
  int size = a.size();
  vector<T> ans(size);
  ans[0] = a[0];
  for (int i = 0; i < size - 1; i++) {
    ans[i + 1] = ans[i] + a[i + 1];
  }
  return ans;
}
long long getaccumnum(vector<long long> accum, int l, int r) {
  if (l == 0) {
    return accum[r];
  } else {
    return accum[r] - accum[l - 1];
  }
}
struct datas {
  long long p;
  long long q;
};
template <class T>
T gcd(T a, T b) {
  if (a == 0) {
    return b;
  } else if (b == 0) {
    return a;
  }
  while (1) {
    if (a < b) swap(a, b);
    if (!b) break;
    a %= b;
  }
  return a;
}
int LCS(string s, string t) {
  int n = s.size();
  int m = t.size();
  vector<vector<int>> dp = vector<vector<int>>(n + 1, vector<int>(m + 1, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }
  return dp[n][m];
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> ans(n, -1);
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] != c[i] && ans[s[i] - 1] != -1) {
      cout << -1 << endl;
      return 0;
    }
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1 && i == 0) {
      ans[i] = 1;
    } else if (ans[i] == -1 && i > 0) {
      ans[i] = 0;
    }
  }
  int aa = 0;
  for (int i = 0; i < n; i++) {
    aa += digitpower(10, n - i - 1) * ans[i];
  }
  cout << aa << endl;
  return 0;
}
