#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265359;
const long long INF = 1e12;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 5;
bool compare(const pair<int, int>& i, const pair<int, int>& j) {
  return i.second < j.second;
}
long long raise(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int n, m, s[10], c[10], num[10];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (num[s[i]] == 0 || num[s[i]] == c[i])
      num[s[i]] = c[i];
    else {
      cout << (-1) << "\n";
      return;
    }
  }
  if (num[1] == 0) {
    cout << (-1) << "\n";
    return;
  }
  for (int i = 1; i <= n; ++i) cout << num[i];
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
