#include <bits/stdc++.h>
using namespace std;
template <typename T>
void dump(T *arr, int h, int w) {
  for (int i = 0, i_len = (h); i < i_len; ++i) {
    for (int j = 0, j_len = (w); j < j_len; ++j) cout << arr[i][j] << "\t";
    cout << "\n";
  }
}
template <typename T>
void dump(T *arr, int a) {
  for (int i = 0, i_len = (a); i < i_len; ++i) cout << arr[i] << "\t";
  cout << "\n";
}
template <typename T>
void dump(vector<T> arr, int a) {
  for (int i = 0, i_len = (a); i < i_len; ++i) cout << arr[i] << "\t";
  cout << "\n";
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second)
    return a.second > b.second;
  else
    return a.first > b.first;
}
int digits(long long num) {
  long long d = 0;
  while (num >= 1) {
    num /= 10;
    d++;
  }
  return d;
}
long long pow_kai(long long a, int n) {
  long long x = 1;
  while (n > 0) {
    if (n & 1) {
      x = x * a;
    }
    a = a * a;
    n >>= 1;
  }
  return x;
}
struct UnionFind {
  vector<int> par;
  vector<int> num_node;
  UnionFind(int N) : par(N), num_node(N) {
    for (int i = 0; i < N; i++) {
      par[i] = i;
      num_node[i] = 1;
    }
  }
  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;
    num_node[ry] += num_node[rx];
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int nodes(int x) { return num_node[root(x)]; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    ans[i] = -1;
  }
  int s, c;
  bool ng = false;
  for (int i = 0, i_len = (m); i < i_len; ++i) {
    cin >> s >> c;
    if (ans[s - 1] != -1 && ans[s - 1] != c) {
      ng = true;
    }
    ans[s - 1] = c;
  }
  if (n != 1 && ans[0] == 0) ng = true;
  int ret = -1;
  if (!ng) {
    for (int i = int(pow(10, n - 1)); i < int(pow(10, n)); ++i) {
      int d = digits(i);
      if (d != n) continue;
      string i_s = "";
      i_s += to_string(i);
      ng = false;
      for (int ii = 0, ii_len = (d); ii < ii_len; ++ii) {
        if (ans[ii] != -1 && (char)(ans[ii]) + '0' != i_s[ii]) {
          ng = true;
        }
      }
      if (ng) continue;
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
