#include <bits/stdc++.h>
using namespace std;

#define inf 2000000000 // 1e17
// 0-indexed
template <class T>
struct Dinic {
  struct edge {
    int to;
    T cap;
    int rev;
  };
  vector<vector<edge>> lst;
  vector<int> completed;
  vector<int> dist;
  Dinic(int n = 1) {
    // if 1-indexed
    //++n;
    lst.resize(n);
    completed.resize(n);
    dist.resize(n);
  }
  bool add(int start, int goal, T capacity) {
    lst[start].push_back(
        (edge){goal, capacity, (int)lst[goal].size()});
    lst[goal].push_back(
        (edge){start, 0, (int)lst[start].size() - 1});
    return 1;
  }
  // dist = time from start to now number
  void distbfs(int start) {
    fill(dist.begin(), dist.end(), -1);
    queue<int> bfsqu;
    dist[start] = 0;
    bfsqu.push(start);
    while(bfsqu.size() > 0) {
      int now = bfsqu.front();
      bfsqu.pop();
      for(int i = 0; i < lst[now].size(); ++i) {
        edge* nowe = &lst[now][i];
        if(nowe->cap > 0 && dist[nowe->to] < 0) {
          dist[nowe->to] = dist[now] + 1;
          bfsqu.push(nowe->to);
        }
      }
    }
  }
  T pathdfs(int now, int goal, T nf) {
    if(now == goal) return nf;
    for(int& i = completed[now]; i < lst[now].size(); ++i) {
      edge* e = &lst[now][i];
      if(e->cap > 0 && dist[now] < dist[e->to]) {
        T ans = pathdfs(e->to, goal, min(nf, e->cap));
        if(ans > 0) {
          e->cap -= ans;
          lst[e->to][e->rev].cap += ans;
          return ans;
        }
      }
    }
    return 0;
  }
  T solve(int start, int goal) {
    T ans = 0, nf = 0;
    while(1) {
      // bfs
      distbfs(start);
      // cannnot go to goal from start
      if(dist[goal] < 0) return ans;
      // reset
      fill(completed.begin(), completed.end(), 0);
      while((nf = pathdfs(start, goal, inf)) > 0) ans += nf;
    }
    return -1;
  }
};

Dinic<int> din;
string u;
int n, m;

int main() {
  cin >> n >> m >> u;
  din = Dinic<int>(n + 2);
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    din.add(n, i, (u[i] == 'R') * a);
    din.add(i, n + 1, (u[i] == 'L') * a);
  }
  for(int i = 0; i < m; ++i) {
    int s, t, b;
    cin >> s >> t >> b;
    --s, --t;
    din.add(min(s, t), max(s, t), b);
  }
  cout << din.solve(n, n + 1) << endl;
  return 0;
}
