#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1e17;
constexpr double PI = 3.141592653589793;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long h, w;
vector<long long> dx = {-1, 0, 1, 0};
vector<long long> dy = {0, -1, 0, 1};
bool isInField(long long x, long long y) {
  bool f = x >= 0 && x < w && y >= 0 && y < h;
  return f;
}
bool compare_first(pair<long long, long long> x, pair<long long, long long> y) {
  if (x.first != y.first) {
    return x.first < y.first;
  } else {
    return x.second < y.second;
  }
}
bool compare_second(pair<long long, long long> x,
                    pair<long long, long long> y) {
  if (x.second != y.second) {
    return x.second < y.second;
  } else {
    return x.first < y.first;
  }
}
struct {
  bool operator()(pair<string, int> x, pair<string, int> y) const {
    return x.second <= y.second && x.first < y.first;
  }
} compare_map;
const long long MAX = 500000000;
const long long MOD = 1000000007;
vector<long long> dijkstra(
    const vector<vector<pair<long long, long long>>>& graph, int start) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  vector<long long> dist(graph.size(), INF);
  dist[start] = 0l;
  pq.push(pair<long long, long long>(dist[start], start));
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int d = p.first;
    int from = p.second;
    if (dist[from] < d) continue;
    for (auto next : graph[from]) {
      int to = next.first;
      int cost = next.second;
      if (dist[from] + cost < dist[to]) {
        dist[to] = dist[from] + cost;
        pq.push(pair<long long, long long>(dist[to], to));
      }
    }
  }
  return dist;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<char> ss(n, 'x');
  bool ok = true;
  for (int i = 0; i < m; i++) {
    s[i]--;
    if (ss[s[i]] != 'x' && ss[s[i]] != c[i]) {
      ok = false;
      break;
    }
    ss[s[i]] = c[i];
  }
  for (auto z : ss) {
    if (z != 'x' && z != '0') {
      break;
    }
    if (z == '0') {
      ok = false;
      break;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (ss[i] == 'x' && i == 0) {
      ss[i] = '1';
    }
    if (ss[i] == 'x') {
      ss[i] = '0';
    }
  }
  string ans(ss.begin(), ss.end());
  int ansi = atoi(ans.c_str());
  int keta = 0;
  int ansi2 = ansi;
  while (ansi2 > 0) {
    keta++;
    ansi2 /= 10;
  }
  if (keta != n) {
    ok = false;
  }
  if (ok) {
    cout << ans;
    cout << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}
