#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;
int second[10], c[10];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int i, n, m, ans = 0;
  cin >> n >> m;
  bool ok = 1;
  map<int, int> make_pair;
  for (i = 1; i <= m; ++i) {
    cin >> second[i] >> c[i];
    if (make_pair.find(second[i]) != make_pair.end()) {
      if (make_pair[second[i]] == c[i]) continue;
      ok = 0;
      break;
    } else {
      make_pair[second[i]] = c[i];
      ans += pow(10, n - second[i]) * c[i];
    }
  }
  if (!ok || !ans)
    cout << -1;
  else
    cout << ans;
  return 0;
}
