#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long inf = 1LL << 60;
const double eps = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(3, vector<int>(0)), b(3, vector<int>(0));
  vector<int> k;
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    a[s - 1].push_back(c);
    if (s == 1 and c == 0 and n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<bool> x(3, false);
  for (int i = 0; i < n; i++) {
    int tmp;
    if (int(a[i].size()) > 0)
      tmp = a[i][0];
    else {
      k.push_back(i);
      x[i] = true;
      continue;
    }
    x[i] = true;
    for (int j = 1; j < int(a[i].size()); j++) {
      if (tmp != a[i][j]) x[i] = false;
    }
  }
  int ans = 0;
  int tmp = 1;
  for (int i = 0; i < n; i++) {
    tmp *= x[i];
  }
  if (tmp) {
    int tmp = 1;
    int cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (int(a[i].size()) > 0) {
        ans += a[i][0] * tmp;
      } else {
        if (i == 0) ans += tmp;
      }
      tmp *= 10;
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
