#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}
template <class T>
void print(T& x) {
  cout << x << '\n';
}
const int MOD = (int)1e9 + 7;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMint() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  if (a > b) {
    swap(a, b);
  }
  return gcd(a, b % a);
}
long long lcm(long long a, long long b) {
  long long g;
  g = gcd(a, b);
  return a * b / g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
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;
}
long long RS(long long N, long long pair<int, int>, long long M) {
  if (pair<int, int> == 0) {
    return 1;
  } else {
    if (pair<int, int> % 2 == 0) {
      long long t = RS(N, pair<int, int> / 2, M);
      return t * t % M;
    } else {
      return N * RS(N, pair<int, int> - 1, M) % M;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N = in();
  int M = in();
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << pow(10, N - 1) << endl;
      return 0;
    }
  }
  int ans = 1000;
  vector<pair<int, int>> p;
  for (int i = 0; i < (M); ++i) {
    int s;
    int c;
    if (s == N && c == 0) {
      ans = -1;
    } else {
      cin >> s >> c;
      p.push_back(make_pair(s, c));
    }
  }
  if (ans < 1000) {
    cout << ans << endl;
    return 0;
  }
  int start;
  if (N == 1) {
    start = 0;
  } else {
    start = pow(10, N - 1);
  }
  for (int i = start; i < pow(10, N); i++) {
    int d[N + 1];
    for (int j = 1; j <= (N); ++j) {
      int a = pow(10, j);
      d[N - j + 1] = (i % a) / pow(10, j - 1);
    }
    for (int j = 0; j < (p.size()); ++j) {
      if (d[p[j].first] != p[j].second) {
        break;
      } else {
        if (j == p.size() - 1) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
