#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
bool compare_a_big(pair<int, int> l, pair<int, int> r) {
  if (l.first != r.first) {
    return l.first > r.first;
  } else {
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int, int> l, pair<int, int> r) {
  if (l.first != r.first) {
    return l.first > r.first;
  } else {
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int, int> l, pair<int, int> r) {
  if (l.second != r.second) {
    return l.second < r.second;
  } else {
    return l.first < r.first;
  }
}
const int INF = 1e9;
const int M = 1000000007;
vector<long long int> fac(300001);
vector<long long int> ifac(300001);
long long int mpow(long long int x, long long int n) {
  long long int ans = 1;
  while (n != 0) {
    if (n & 1) ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
long long int comb(long long int a, long long int b) {
  fac[0] = 1;
  ifac[0] = 1;
  for (long long int i = 0; i < 300000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;
    ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M;
  }
  if (a == 0 && b == 0) return 1;
  if (a < b || a < 0) return 0;
  long long int tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
int pow(int a, int b) {
  if (b == 0)
    return 1;
  else {
    return a * pow(a, b - 1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int i;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int ans[n];
  for (i = 0; i < n; i++) {
    ans[i] = 10;
  }
  int isfalse = 0;
  for (i = 0; i < m; i++) {
    if (ans[s[i] - 1] > 9) {
      ans[s[i] - 1] = c[i];
    } else {
      if (ans[s[i] - 1] != c[i]) {
        isfalse = 1;
      }
    }
  }
  if (isfalse) {
    cout << -1 << endl;
  } else if (n > 1 && ans[0] == 0) {
    cout << -1 << endl;
  } else {
    int num = 0;
    for (i = 0; i < n; i++) {
      if (ans[n - 1 - i] == 10 && i == n - 1)
        num += pow(10, i);
      else if (ans[n - 1 - i] != 10)
        num += ans[n - 1 - i] * pow(10, i);
    }
    cout << num << endl;
  }
}
