#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;
template <typename T>
inline void dbg(T a) {
  cout << setprecision(12) << a << ' ';
}
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
double d;
int main() {
  cin >> n >> m;
  int answ[n];
  fill(answ, answ + n, -1);
  int c[m], s[m];
  for (ll i = (ll)(0); i < (ll)(m); ++i) {
    cin >> s[i] >> c[i];
    if (n > 1 && s[i] == 1 && c[i] == 0) {
      dbg(-1);
      return 0;
    }
    if (answ[s[i] - 1] != -1 && answ[s[i] - 1] != c[i]) {
      dbg(-1);
      return 0;
    }
    if (answ[s[i] - 1] == -1) {
      ans += pow(10, (n - s[i])) * c[i];
      answ[s[i] - 1] = c[i];
    }
  }
  if (answ[0] == -1) {
    ans += pow(10, n - 1);
  }
  dbg(ans);
}
