#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
struct Tll {
  LL first, second, third;
};
struct Fll {
  LL first, second, third, fourd;
};
void YN(bool f) {
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void yn(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
struct Edge {
  LL to, cost;
};
struct edge {
  LL from, to, cost;
};
vector<vector<LL>> g, rev;
vector<edge> edges;
vector<LL> v;
map<LL, LL> ma;
set<LL> st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[510000], b[510000],
    dp[50000];
string str, ss;
bool f;
char c;
int main() {
  cin >> n;
  cin >> m;
  for (LL i = 0; i < n; i++) a[i] = -1;
  for (LL i = 0; i < m; i++) {
    LL x, y;
    cin >> x >> y;
    x--;
    if (a[x] != -1 && a[x] != y) {
      cout << -1 << endl;
      return 0;
    }
    a[x] = y;
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    LL cur = i;
    for (int j = 0; j < n; j++) {
      if (a[n - j - 1] != -1 && cur % 10 != a[n - j - 1]) break;
      cur /= 10;
      if (n - 1 == j) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
